Object not initialized [.NET Business Connector]

687 Views Asked by At

Here is my code :

AxaptaObject dict = (AxaptaObject)DynAx.CallStaticClassMethod("Dictionary", "new");
object id = (object)dict.Call("enumName2Id", "TimeZone");
AxaptaObject dictEnum = (AxaptaObject)DynAx.CallStaticClassMethod("DictEnum", "new", id);
string s = (string)dictEnum.Call("index2Label", "2");

I am getting the following error:

Error executing code: Dictionary object not initialized.

Why is it throwing that error during initialization of Dictionary object? Kindly help.

1

There are 1 best solutions below

0
On BEST ANSWER

Got it!

Code is as follows :

int enumId = (int)ax.CallStaticClassMethod("Global", "enumName2Id", enumName);
AxaptaObject dictEnum = (AxaptaObject)ax.CreateAxaptaObject("DictEnum", enumId);
return (string)dictEnum.Call("index2Label", index);

You have to use "AxaptaObj.CreateAxaptaObject". This way you can indirectly write X++ code in C# for small jobs such as these. I'm not sure about performance factor.