Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

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

Posted on by 93
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 229,918 Most Valuable Professional 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 93 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 229,918 Most Valuable Professional 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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,113 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,918 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans