Reputation: 11
Below error while deserializing result set(tuple) in WCF function.
There was an error while trying to deserialize paramenter XXX. Please see InnerException for more details.
'System.Tuple' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.
Below is the tuple definition.
Public Class XXX Public Property aaa As New List(of Tuple(of bbb,ccc)) End class
Upvotes: 1
Views: 667
Reputation: 1273
Untimely, you need to make a class instead of using a Tuple. The exception says you cannot use a Tuple because A) It's not marked with the DataContract
Attribute and B) Because it doesn't have a parameter-less constructor. So, a Tuple<int,string>
cannot be set to a new Tuple<int,string>();
If the class you sent via WCF was like this...
public class MyClassToSendThroughWcf
{
public tuple<int,string> MyData {get;set;} //The tuple here is problem, replace with the class below...
}
You could replace the type of "MyData" with a class that does the same thing like this...
public class MyClassToUseWithWcf
{
public MyClassToUseWithWcf(){}
public MyClassToUseWithWcf(int i, string s)
{
Item1 = i;
Item2 = s;
}
public int Item1 {get;set;}
public string Item2 {get;set;}
}
Now, both classes have default constructors, so it can be serialized. I suggest avoiding tuples anyway.
Upvotes: 1