Sunday, July 20, 2008

A word to the wise: careful of your types for DataMembers

I was getting a pretty strange error in MRDS. I was trying to use the REST (representational state transfer) to transfer an array of objects, when it failed on compilation:
private object[] _list;

[DataMember]
public object[] List
{
get { return _list; }
set { _list = value; }
}
It throws an error:

Error 1 Unable to Clone System.Object at Microsoft.Dss.Services.ContractManager.TransformUnit.WriteTransformMethod(TextWriter w, String prefix, DssClassType dssClass, CopyK ...\Microsoft Robotics Dev Studio 2008\projects\<ServiceName>1\EXEC <ServiceName>

Error 2 The command ""...\Microsoft Robotics Dev Studio 2008\bin\dssproxy.exe" /dll:"...\Microsoft Robotics Dev Studio 2008\bin\<ServiceName>.Y200#.M##.dll" /vstarget:VS2008 /proxyprojectpath:"...\Microsoft Robotics Dev Studio 2008\projects\<ServiceName>\Proxy " /keyfile:"...\Microsoft Robotics Dev Studio 2008\samples\mrisamples.snk" /binpath:". " /referencepath:"...\Microsoft Robotics Dev Studio 2008\bin\ " /referencepath:"...\Microsoft Robotics Dev Studio 2008\bin\ " " exited with code 10. <ServiceName>


If you compile it again, it seems fine. It's not fine. Remove it. I also got an error, which revealed the problem, when trying a similar move with an ArrayList object:
private ArrayList _list;

[DataMember]
public ArrayList List
{
get { return _list; }
set { _list = value; }
}

Error 1 Invalid [DataMember] field. ...\Microsoft Robotics Dev Studio 2008\projects\<ServiceName>\EXEC <ServiceName>

Error 2 The command ""...\Microsoft Robotics Dev Studio 2008\bin\dssproxy.exe" /dll:"...\Microsoft Robotics Dev Studio 2008\bin\<ServiceName>.Y200#.M##.dll" /vstarget:VS2008 /proxyprojectpath:"...\Microsoft Robotics Dev Studio 2008\projects\<ServiceName>\Proxy " /keyfile:"...\Microsoft Robotics Dev Studio 2008\samples\mrisamples.snk" /binpath:". " /referencepath:"...\Microsoft Robotics Dev Studio 2008\bin\ " /referencepath:"...\Microsoft Robotics Dev Studio 2008\bin\ " " exited with code 20. <ServiceName>


The right way to deal with this kind of situation is to use the Array object. You set the array by using the Array.CreateInstance method.

0 incoming messages (comments):