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:

Azure Hosted pipeline - Update Artifacts (NuGet) for version update

 Step-by-Step Guide to Updating or Creating Artifacts for a Hosted Pipeline In this blog, we’ll walk you through the process of updating or ...