Skip to main content

Notifications

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!

  • Suggested answer
    José Quintero Profile Picture
    160 on at
    RE: Object 'CLRObject' could not be created calling method from Ax 2009 to C#

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

  • Verified answer
    Martin Dráb Profile Picture
    232,068 Most Valuable Professional on at
    RE: Object 'CLRObject' could not be created calling method from Ax 2009 to C#

    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.

  • Verified answer
    huijij Profile Picture
    19,811 on at
    RE: Object 'CLRObject' could not be created calling method from Ax 2009 to C#

    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

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,289 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,068 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans