web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Object 'CLRObject' could not be created calling method from Ax 2009 to C#

(0) ShareShare
ReportReport
Posted on by 160

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!

I have the same question (0)
  • Verified answer
    huijij Profile Picture
    19,813 on at

    Hi José,

    When you call C# methods from Ax,you have to create a reference from the X++ project to the C# project:

    docs.microsoft.com/.../write-business-logic

  • Verified answer
    Martin Dráb Profile Picture
    239,656 Most Valuable Professional on at

    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.

  • Suggested answer
    José Quintero Profile Picture
    160 on at

    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!.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 587

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 568 Super User 2026 Season 1

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 561 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans