1
votes

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

1
What does the inner exception say, this does not provide enough information. - Mark
Can you post the de-serializing code? - Deepu Madhusoodanan
Public Function EndXXX(ByVal result As System.IAsyncResult) As XXX Implements EndXXX Dim _args((0) - 1) As Object Dim _result As XXX = CType(MyBase.EndInvoke("XXX", _args, result), XXX) Return _result End Function - beginer

1 Answers

1
votes

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.