Skip to main content

Notifications

Announcements

No record found.

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

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

(0) ShareShare
ReportReport
Posted on by 97
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 230,354 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 97 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 230,354 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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans