Skip to main content
Microsoft Dynamics AX forum
Unanswered

Reading list from dll to X++. How to resolve invalid cast exception error in x++.

editSubscribe (0) ShareShare
ReportReport
Posted on by 91
Hi All,

In dll,

  public class ErrorMessage
        {
            public string type { get; set; }
            public string code { get; set; }
            public string category { get; set; }
            public string message { get; set; }
            public string status { get; set; }
        }
        public List<ErrorMessage> errorMessages { get; set; }
 
in ax,
 
CLRObject ListError = new CLRObject(/System.Collections.Generic.List`1[System.Object]/);
 ClrObject enumeratorError;

IT_ZatcaIntegration.ErrorMessage  errorMessage = new  IT_ZatcaIntegration.ErrorMessage();
 
 
  if(ListError)
                {
                enumeratorError = ListError.GetEnumerator();
                while (enumeratorError.MoveNext())
                {
             //    errorMessage = enumeratorError.get_Current();
                integrationLineLog.ErrorCategory = errorMessage.get_category();
                integrationLineLog.ErrorCode = errorMessage.get_code();
                integrationLineLog.ErrorMessage = errorMessage.get_message();
                integrationLineLog.ErrorStatus  = errorMessage.get_status();
                integrationLineLog.ErrorType = errorMessage.get_type();
                integrationLineLog.insert();
                }
                }
 
 
while reading the list from dll in ax i am facing the below error message.
Could anyone please help me on this to resolve this issue?

  • Martin Dráb Profile Picture
    Martin Dráb 222,570 Super User on at
    Reading list from dll to X++. How to resolve invalid cast exception error in x++.
    Okay, so it's about AX 2012. And I guess the difference isn't between a runnable class and a batch, but between running the code as X++ or CIL. Note that you can test such things; you can run code in CIL without a batch.
     
    Have you generated CIL after compiling X++?
     
    Please share your actual code, because your screenshot shows that the exception is thrown by a call that you don't have in code that you shared before (and it wouldn't ever reach the line of code).
  • PJ JohnPaul Profile Picture
    PJ JohnPaul 91 on at
    Reading list from dll to X++. How to resolve invalid cast exception error in x++.
    Hi @martin,

    Thanks for your reply. 
    Error is throwing in the highlighted line.
    This same code working fine when i am running from runnable job, but in bacth processing i am facing the issue.

    Ax version : 
     
     

  • Martin Dráb Profile Picture
    Martin Dráb 222,570 Super User on at
    Reading list from dll to X++. How to resolve invalid cast exception error in x++.
    Which line in 785? Which version of AX is it?
     
    I see you created a new list and iterate its elements, but there is never any if you never add any element there.
     
    Avoid generic types if possible; .NET Interop doesn't support them.

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,045 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,570 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans