Yesterday, I was working on integration, and everything was going fine. However, when I tried to retrieve a string from the DataContract, it threw an error: “Type ‘Class’ is not supported by the serializer.” The issue persisted even when I used Newtonsoft. The rest of the logic was functioning correctly.
Eventually, I discovered that the issue was due to missing AX 2012 attributes on the list’s getter/setter or parameter. Once I added those attributes, the actual getter/setter started working as expected.
[
DataMemberAttribute('transactions'),
DataCollectionAttribute(Types::Class, classStr(DSTTransactionDC))
]
public List Parmtransactions(List _transactions = transactions)
{
transactions = _transactions;
return transactions;
}
I have to add following
AifCollectionTypeAttribute('_transactions', Types::Class, classStr(DSTTransactionDC)),
AifCollectionTypeAttribute('return', Types::Class, classStr(DSTTransactionDC))
After that getter setter become something similar
[
DataMemberAttribute('transactions'),
DataCollectionAttribute(Types::Class, classStr(DSTTransactionDC)),
AifCollectionTypeAttribute('_transactions', Types::Class, classStr(DSTTransactionDC)),
AifCollectionTypeAttribute('return', Types::Class, classStr(DSTTransactionDC))
]
public List Parmtransactions(List _transactions = transactions)
{
transactions = _transactions;
return transactions;
}
after this change, datacontract easily serialise.
Also change attribute at class header from datacontracattribute to dataContract.
Hope you like this post.