What’s your version of AX? If AX2012, is the code on server running as X++ or CIL? Can you confirm that you can catch X++ errors without troubles even on server?
I am using AX 2012. I can catch error defined But not CLR for my following code.
Basically i am passing sid from userinfo table as parameter and trying to disable AD account. My server account has not got enough permissions to disable AD.
So I want to catch that error which is “System.UnauthorizedAccessException: Access is denied”.
The error is seen in the batch job log.
"
public void disableADAcc(Sid ADsid)
{
System.DirectoryServices.AccountManagement.PrincipalContext p;
System.DirectoryServices.AccountManagement.UserPrincipal u;
System.Exception ex;
Set permissionSet;
Exception exception;
str message;
;
try
{
// permissionSet = new Set(Types::Class);
// permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
//CodeAccessPermission::assertMultiple(permissionSet);
p = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType::Domain);
u = System.DirectoryServices.AccountManagement.UserPrincipal::FindByIdentity(p, System.DirectoryServices.AccountManagement.IdentityType::Sid, ADsid);
//disable active directory account
u.set_Enabled(false);
u.Save();
//CodeAccessPermission::revertAssert();
}
catch(exception::CLRError)
{
this.getClrErrorMessage();//copied this method from aifutil class
}
How do you verify that the exception get caught? AifUtil::getClrErrorMessage simply returns a string and you don’t do anything with it, therefore your code simply catches and swallows the exception without any observable output.
The only idea I have is that the code is in a transaction. When an exception is thrown in a transaction, nothing else inside the transaction is executed, including catch statements.
I would also suggest walking through the code in debugger to see exactly what’s happening there (whether any exception is thrown or not, what code gets executed after that and so on).