Getting error in calling AIF Service via C# console application

Hi,

I have developed one class using Business Operation Framework to do some business requirement like copy company. I have added this class in Service and Service group. I have deployed this service group. Now I am consuming this service via C# console application in visual studio 2013 and passing only Data Area ID as a parameter. But when I run the console application, getting below error.

System.ServiceModel.FaultException: Unable to cast object of type ‘Microsoft.Dyn****amics.Ax.Xpp.Set’ to type ‘Microsoft.Dynamics.Ax.Xpp.List’.

Can anyone help in this?

Regards,
Janak Talekar

You’re using a Set somewhere where a List is expected. It’s just rephrasing what the error says, but it’s impossible to be more specific without more information from you.

Hi Martin,

Thanks for your reply.

If you want source code for analyze the same then I can share with you.

Regards,

Janak Talekar

I don’t need anything, but if you’re unable to debug your code and want somebody else to review it, it won’t work if you don’t make it available.

Nevertheless debugging is usually easier than a static code review.

Hi Martin,

Thanks for your prompt reply and suggestion.

I have debug my code in visual stuido and found the exact line on which it gives an error.

I am using Sys Operation Framework and expose this class as a service and consuming from C# console application.

It is a standard Data Export import class.

\Classes\SysDataExportBase\exportSCscSupertypes

protected Integer exportSCscSupertypes(tableId _tableId)

{

counter recCount = 0;

List subtypes;

ListEnumerator le;

SysQueryRun sqr;

SysDictTable thisTable;

boolean isFirst = true;

// export subtypes

if ( tableId2SubtypeListMap.exists(_tableId) )

{

subtypes = tableId2SubtypeListMap.lookup(_tableId); //Getting error on this line

**//**System.InvalidCastException was unhandled by user code

Message: An exception of type ‘System.InvalidCastException’ occurred in Dynamics.Ax.Application.dll193.netmodule but was not handled in user code

Additional information: Unable to cast object of type ‘Microsoft.Dynamics.Ax.Xpp.Set’ to type ‘Microsoft.Dynamics.Ax.Xpp.List’.

le = subtypes.getEnumerator();

while(le.moveNext())

{

if ( !this.getTableExported(le.current()) )

{

this.exportSCscSupertypes(le.current());

}

}

}

// export records associated with subtypes

if ( tableId2SubtypeListMap.exists(_tableId) )

{

thisTable = new SysDictTable(_tableId);

subtypes = tableId2SubtypeListMap.lookup(_tableId);

le = subtypes.getEnumerator();

while(le.moveNext())

{

sqr = this.createSCscQueryRun(_tableId,le.current(),false);

if ( sqr!=null )

{

recCount += this.exportTable(thisTable,null,sqr,!isFirst);

isFirst = false;

}

}

this.setExportedRecCount(_tableId,recCount);

}

return recCount;

}

Can you suggest some solution for this?

Regards,

Janak Talekar

It seems that tableId2SubtypeListMap is a collections of Set instances, while you’re trying to use it as a collection of List instances. Change the type of subtypes to Set (and change related code accordingly, i.e. use SetEnumerator) and it should all work.

If you used a debugger, it would be completely obvious there. Not using debugger makes your life more difficult than necessary.