Monday 23 September 2013

CLR / IL Exceptions in Dynamics AX X++

CLR exceptions are due to .Net Business connector.
when AX tried to call something by reflection but the called method threw an exception.

To understand what failed, you should find what was called and what was the exception.

 1. Catch the exception (by catch (Exception::CLRError)).
 2. Get the CLR exception and look into its InnerException property.
AifUtil::getClrErrorMessage()
is usually the easiest way to do that.

 Eg:
 static void RaiseCLRException(Args _args)
 {
     ;
     //Necessary if executed on the AOS  new InteropPermission(InteropKind::ClrInterop).assert();
     try
    {
         //This will cause an exception
         System.Int32::Parse("abc");
    }
    catch(Exception::CLRError)
    {
     AifUtil::getClrErrorMessage(); 
     //Access the last CLR
      Exception info(CLRInterop::getLastException().ToString());
   }
   //Revert CAS back to normal CodeAccessPermission::revertAssert();
 }

No comments:

Update NuGet package to new MS D365FO version

1. Import the NuGet package files from LCS for that particular version please take the PU version files only. a. Goto LCS-->Asset Libra...