Announcements
Hello:
I am new calling C# methods from Ax 2009.
I created a new method in C#. But, when I put the code
send = new AXV5ElectronicInvoice.Send();
It send the message Object CLRObject could not be created
The C# code is simple:
public class Send { public string returnValue; public void SendDocument(String _User, String _Password, DocumentoElectronico documentoElectronico) { String returnValue; //System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; try { System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; AXV5ElectronicInvoice.TfhkaPaWebService.Service service = new Service(); EnviarResponse enviarResponse = new EnviarResponse(); enviarResponse = service.Enviar(_User, _Password, documentoElectronico); returnValue = " "; //return returnValue; } catch(Exception ex) { returnValue = "Error"; //return returnValue; } }
What could be generate this error?.
How I catch the clrInterop message? I put try catch but the error goes directly to Info class.
Regards!
Hi every one!:
Ok, I got the message finally using catch without specifying CLR or ERROR.
The main issue was that the class was running on server.
The server had an old version of dll.
That's was the issue.
Regards and thanks!.
You're right in thinking that learning how to catch CLR exceptions is very important. Use try/catch block and catch CLRError. There are a few way how to get details of the exception - you can use AifUtil::getClrErrorMessage(), for example:
try { ... } catch(Exception::CLRError) { throw error(AifUtil::getClrErrorMessage()); }
By the way, make sure that the try/catch block isn't in a transaction, because you wouldn't be able to catch exceptions there.
I'm sure that project references weren't supported in AX 2009 and I'm not even sure if there was "Refernces" node in AOT. Nevertheless it seems the assembly was found successfully and that the problem is in something else.
Hi José,
When you call C# methods from Ax,you have to create a reference from the X++ project to the C# project:
André Arnaud de Cal...
293,289
Super User 2025 Season 1
Martin Dráb
232,068
Most Valuable Professional
nmaenpaa
101,156
Moderator