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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Error: CLR object cannot be marshaled to Microsoft Dynamics anytype.

(0) ShareShare
ReportReport
Posted on by 3,850


Hello.

I have created a static method in a class, as the code below is showing.

He is without any errors, just Warning message: "MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Microsoft.Dynamics.AX.ManagedInterop", "x86". This mismatch may cause runtime failures. Please consider changing" who I think it's just a minor thing, because I'm running on Remote Desktop on the AX2012R3 Demo VM

I created a job who is like this:

static void Job1(Args _args)

{

MyClass::notMarshall();

}

 

But I got error message - and notice, it's TWO times for ONE run:

CLR object cannot be marshaled to Microsoft Dynamics anytype.

CLR object cannot be marshaled to Microsoft Dynamics anytype.

As it is descripted in the code below, who I fount in a book from PACKT publishing:

 // Let AIFUtil create the proxy client because it uses the VSAssemblies path for the config file

       client = AifUtil::createServiceClient(type);

But that don't seems to work.

I have also tried to marshall throgh code by using information from this link: http://msdn.microsoft.com/en-us/library/bb986175(v=ax.10).aspx - and I used how to marshall System.String example. When I did that I just got an info windows with just NOTHIN in it - empty message with in Info icon.

Have anyone clue about whatr is happening here: Do I have to do some arrangements about connecting with the webservice on some unusual way?

So I have to use the client and close him at the end like client.Close();  ?

Do I have to set some permission like this:

    permission = new InteropPermission(InteropKind::ClrInterop);
    permission.assert();

and at the end of the code:

    CodeAccessPermission::revertAssert();

The belowed code is like the PACKT book introduce, and I have integrade him by instruction from the service provider:

public static void notMarshall()

{

   // Determine variable from .NET Service Ref

   MyNamespace_1.Client   client;

   MyNamespace_1.SetInfo   input;

   MyNamespace_1.GetInfo       output;

 

   // determine system variables

   System.ServiceModel.Description.ServiceEndpoint endpoint;

   System.ServiceModel.EndpointAddress             endpointAddress;

   System.Exception                              exception;

   System.Type                                     type;

   ;

   //Initialising

   input = new MyNamespace_1.SetInfo();

   output = new MyNamespace_1.GetInfo();

 

   try

   {      

       //get the .NET type of the client proxy

       type = CLRInterop::getType('MyNamespace_1.Client');

      

       // Let AIFUtil create the proxy client because it uses the VSAssemblies path for the config file

       client = AifUtil::createServiceClient(type);

      

       //create and endpoint address, This should be a parameter stored in the system

       endpointAddress = new System.ServiceModel.EndpointAddress("https://securep.austaxagency.com.au/VAT/WS/VATService.svc");

      

      

      

       // Set endpoint

       endpoint = client.get_Endpoint();

      

       //set endpoint address

       endpoint.set_Address(endpointAddress);

 

       //call the parameters

       input.set_Id('1234567890');

       input.set_softwVers("version01");

       input.set_password("passvord");

      

       //Use the getAnyTypeForObject to marshal the System.String to an AX anytype

       info(strFmt('%1', CLRInterop::getAnyTypeForObject(output.get_Error())));

   }

  

   catch(Exception::CLRError)

   {

       // Get the .NET Type Exception

       exception = CLRInterop::getLastException();

 

       // Go through the inner exceptions

       while(exception)

       {

           // Print the exception to the infolog

           info(CLRInterop::getAnyTypeForObject(exception.ToString()));

 

           // Get the inner exception for more details

           exception = exception.get_InnerException();

       }

 

   }

}

 

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    236,240 Most Valuable Professional on at
    RE: Error: CLR object cannot be marshaled to Microsoft Dynamics anytype.

    Simply put: Is Error == null?

    I'm almost sure it is. The code would work if Error contained a string, but it contains null instead.

  • Sandri Profile Picture
    3,850 on at
    RE: Error: CLR object cannot be marshaled to Microsoft Dynamics anytype.

    Hello martin

    Sure I want your help:

    I just have to admit that after looong working day I can't remember how I find this error property. Can you inform me about that?

    I surly want all your help that you want to give.

  • Martin Dráb Profile Picture
    236,240 Most Valuable Professional on at
    RE: Error: CLR object cannot be marshaled to Microsoft Dynamics anytype.

    Okay, if you don't want to tell me how the Error property is defined and what its value is, I can't force you.

    My opinion is that it contains null, but because I can't look into your object, there is nothing more I can do for you. Good night.

  • Sandri Profile Picture
    3,850 on at
    RE: Error: CLR object cannot be marshaled to Microsoft Dynamics anytype.

    Hi Martin.

    Both ways don't work with this error: CLR object cannot be marshaled to Microsoft Dynamics anytype.

    1) str myString = output_getError();

    info(myString);

    2) System.String myString = output_getError();

    info(myString);

    3) I have also tried to marshall code between system.string and string like this:

    System.String systemString = output_getError();

    string myString = systemString

    info(myString). - and that doesn't change anything. same error as above.

    It have something to do with right marshal code on the right way.

    The reason that i mention the boolean and int vars, i use just boolean and int (Not System. types) and that work, I got respond. I dind't have to use System types. if I do right authentication I got boolean to true and int to 10 (amount). and that is right. But wrong authentication give me boolean to false and int to 0

  • Martin Dráb Profile Picture
    236,240 Most Valuable Professional on at
    RE: Error: CLR object cannot be marshaled to Microsoft Dynamics anytype.

    You said that this code doesn't work:

    str myString = output_getError();
    info(myString);
    

    What "doesn't work" exactly means? Also, can you tell me how exactly is the property defined in the .NET library and what's its actual value? Isn't it null? (Please, I don't want to ask for the third time...).

    By the way, boolean is an X++ type and System.Boolean is a .NET type. Do you understand that you're dealing with two different type systems?

  • Sandri Profile Picture
    3,850 on at
    RE: Error: CLR object cannot be marshaled to Microsoft Dynamics anytype.

    Hello Martin.

    Thanks for all your help first of all.

    I did some different approach - took your advice and try this approach instead: technet.microsoft.com/.../hh500185(d=printer).aspx

    According what you said about the code then I have just one error here:

    1) I tried to switch client type:

    System.Type     type; and also tried: CLRObject     type;

    2) The id, softwareversion and passw is perfectly OK because I got an answer (both System.Type version and CLRObject version)

    3) I declared three vars: int myInteger;   str myString;   boolean myBoolean; (because the .net type is of this type.

    This code don't work:

    myString = output_getError();

    info(myString);

    -Notice: both int and boolean are declared in the same way (with strfmt function of course) and they are not System.Boolean nor System.Int

    I tried to change the myString to System.String, I tried to add functions like you said, but I got error about: CLR object cannot be marshaled to Microsoft Dynamics anytype. (both when CLRObject is used as type variable and System.Type also).

    But otherwise the service is going smooth. On boolean var, I got true - so the message went through! - I just can't see the error message who is string.

    But for your information this is the boolean declerataion:

    myBoolean = output.get_Succseed();

    info(strfmt("Success? : %1", myBoolean));

     

    What can I do with the string variable!!!!

  • Martin Dráb Profile Picture
    236,240 Most Valuable Professional on at
    RE: Error: CLR object cannot be marshaled to Microsoft Dynamics anytype.

    First of all, I didn't get why you're using getAnyTypeForObject() at all. What you should do is using marshalling between X++ str and .NET System.String types by using the assignment operator. So you would write something like str s = output.get_Error(), if Error is a property of type System.String.

    Nevertheless info() in AX 2012 is able to handle that, so you should be able to skip all your magic and write simply info(output.get_Error()). I tested it with the following example:

    System.String s = "abcd";
    info(s.ToUpperInvariant());

    Please try the example by yourself.

    Review the return type in your .NET library and tell us what value is in Error when your code fails. Also extract only the problematic part of your code and don't debug nor post here anything else.

  • Sandri Profile Picture
    3,850 on at
    RE: Error: CLR object cannot be marshaled to Microsoft Dynamics anytype.

    Hi Martin.

    I think the blamer is this line:

    //Use the getAnyTypeForObject to marshal the System.String to an AX anytype

          info(strFmt('%1', CLRInterop::getAnyTypeForObject(output.get_Error())));

    1) When start to type the line like this:

    info(strFmt('%1', CLRInterop::getAnyTypeForObject(output.get_error(

    the Intellisense say: [string get_error()

    BUT:

    When I fill inn the line like this:

    info(strFmt('%1', CLRInterop::getAnyTypeForObject(output.get_error(   ))); (I'm changing the method in the line so I dont need to clear all the ))) out if you understand, but then.

    the intellisese said: [static anytype get anytypeForObject(CLRObject _clrObject)]

    2) I tried to switch method like this:

    info(strFmt('%1', CLRInterop::getAnyTypeForObject(output.get_AmountOfRecords())));

    The intellisense say that Amount of record is Integer.

    And I run that - then I don't get the marshall error - just InfoDialog with 0

    But the same story if I fill into the line with the closing ))) the intellisese say CLRObject like in demo 1.

    Because in demo 2 I got 0 - I am sure that I haven't contact the service provider because if so I should have the number 1 not 0.

  • Martin Dráb Profile Picture
    236,240 Most Valuable Professional on at
    RE: Error: CLR object cannot be marshaled to Microsoft Dynamics anytype.

    A usual question: what are lines throwing the errors? Knowing that it's somewhere in notMarshall() is not enough. Also don't forget to tell us which types are involved at these lines.

    Note that marshalling works with the assignment operator (=), not necessarily in other places such as method calls.

  • Suggested answer
    Joris dG Profile Picture
    17,775 on at
    RE: Error: CLR object cannot be marshaled to Microsoft Dynamics anytype.

    Is your VS project with the MyNamespace_1 set to output  AnyCP, x86 or x64?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
Guy Terry Profile Picture

Guy Terry 2 Moderator

#1
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans