we are using RetailCommonWebAPI for JSON string parsing in one class.
at non-batch mode, code works fine. however in batch mode inside class RetailCommonWebAPI during hashtable conversion from CLRObject throws exception.
tried to allowed assert persmission before method call but after permission also its failing.
kindly help
What exception?
What’s the version of your AX?
Hi Martin,
AX version is : ax 2012 R3
error is :Object must implement IConvertible
Thanks
Neetu
It seems that you’re trying to convert to an incompatible type. AX runtime doesn’t care much about types and it allows even logically invalid assignments, but CLR (the runtime environment executing CIL) uses much stricter type control.
If you need more specific advice, please show us your code and tell us which statement is throwing the error.
Hi Martin,
Below lines of code calling RetailCommonWebAPI class
public static array getArrayFromJson(str _json)
{
str json;
int i,jsonSubstrNo;
TextBuffer textBuffer;
container conJson;
Array jsonArray = new Array(Types::Class);
json = _json;
textBuffer = new TextBuffer();
textBuffer.setText(json);
while (textBuffer.nextToken(0, “{,}”))
{
conJson += “{” + textBuffer.token() + “}”;
}
for (i = 1; i <= conLen(conJson); i++)
{
jsonArray.value(i, RetailCommonWebAPI::getMapFromJsonString(conPeek(conJson, i)));
}
return jsonArray;
}
example of _json input : “City”:“TestNickName”,“Age”:“34”,“Street”:“new”
exception is throwing inside method RetailCommonWebAPI::getMap
at deserializedCollection = new System.Collections.Hashtable(_dict);
Thanks
Neetu
The problem is passing the weakly-typed CLRObject to Hashtable’s constructor. I suggest you change the type of getMap’s parameter (_dict) from CLRObject to System.Collections.IDictionary.
HI Neetu, was your issue resolved by the fix that Martin has suggested? I’m having the same issue.
Hi Deo,
Yes, it worked for my issue.
Neetu
After many trials and errors. I found a solution that seems to work for me. I was getting a conversion error in the convertCLRObjectToContainer() method after changing the parameter type of the getMap() method as Martin suggested. However, it seemed to only have issues if that _clrObject was an Enum type. So I change the following lines in convertCLRObjectToContainer() to this:
//stringValue = _clrObject; <- this line fails, replace with below
switch (typeOf(_clrObject))
{
case Types::Enum:
stringValue = enum2Value(_clrObject);
break;
default:
stringValue = _clrObject;
break;
}