Hi all,
I’m calling the function CLRInterop::getObjectForAnyType() and kept getting the error “Microsoft Dynamics anytype cannot be marshaled to CLR Object”. I don’t know what I’m doing wrong here so anyone out there knows please help, thanks. Both classes are set to run on server. I’m using on-prem Dynamics AX 2012 R3.
Below are my code:
The contract class:
[DataContractAttribute]
public class DzungXmlContract
{
CustAccount custAccount;
Name name;
}
[DataMemberAttribute(“CustomerAccount”)]
public CustAccount parmCustAccount(CustAccount _custAccount = custAccount)
{
custAccount = _custAccount;
return custAccount;
}
[DataMemberAttribute(“Name”)]
public Name parmName(Name _name = name)
{
name = _name;
return name;
}
The business logic class:
public class DzungXmlTestClass
{
}
public str testXml()
{
System.Object clrContract;
str serialized;
InteropPermission permission;
DzungXmlContract contract;
permission = new InteropPermission(InteropKind::ClrInterop);
permission.assert();
contract = new DzungXmlContract();
contract.parmName(“Test”);
contract.parmCustAccount(“ABC123”);
clrContract = CLRInterop::getObjectForAnyType(contract); // This line throws the error.
serialized = ContractSerializer::Serialize(clrContract); // .Net xml serializer.
CodeAccessPermission::revertAssert();
return serialized;
}
The job:
static void DzungXmlTestJob(Args _args)
{
str result;
DzungXmlTestClass test = new DzungXmlTestClass();
result = test.testXml();
info(result);
}