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:

Import and Export file from BLOB storage Account(Azure) in D365 F&O using X++

  Import and Export file from BLOB storage Account in D365 F&O using X++ Import: /// <summary> /// MKInventQualityOrderLineService...