System.Threading.Tasks.Task`1[System.String]' cannot be serialized RRS feed

  • Question

  • Hi,

    I have created a WCF service and deployed in two windows 2008 R2 servers. Both has .Net framework 4.0.

    In one of the server the WCF is working fine. In the other server i am getting the below exception.

     Exception type: InvalidDataContractException
        Exception message: Type 'System.Threading.Tasks.Task`1[System.String]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.  If the type is a collection, consider marking it with the CollectionDataContractAttribute.  See the Microsoft .NET Framework documentation for other supported types.

    Can you please give me some information what needs to be changed?


    Thursday, June 27, 2013 6:06 AM


All replies

  • The support for Task-based asynchronous operations is only available in the .NET Framework 4.5.
    Thursday, June 27, 2013 8:43 AM
  • That doesn't explain why it would be working on one server and not on another. I am seeing the same message on a service that has been running fine all along. I installed a new *client* (didn't touch the service running on another machine) and started getting this message. I think the main thing that has changed is the build environment.
    • Edited by BlueMonkMN Wednesday, September 4, 2013 4:42 PM
    Wednesday, September 4, 2013 4:42 PM
  • If you use the SvcUtil.Exe tool to generate your proxy code for the client add the flag /synconly . That will skip the *Async methods from the proxy code.

    Alternatively you can delete any *Async stub and delegate (like:   

        [System.ServiceModel.OperationContractAttribute(Action="http://DvSysTec.JobMan.Service/ICalculator/Add", ReplyAction="http://DvSysTec.JobMan.Service/ICalculator/AddResponse")]
        System.Threading.Tasks.Task<double> AddAsync(double n1, double n2);
    // ....
        public System.Threading.Tasks.Task<double> AddAsync(double n1, double n2)
            return base.Channel.AddAsync(n1, n2);
    ) manually. The effect is in both cases the same.

    <style>FB_Addon_TelNo{ height:15px !important; white-space: nowrap !important; background-color: #0ff0ff;}</style>
    • Edited by StefanDvs Saturday, October 26, 2013 7:05 PM typo
    Saturday, October 26, 2013 7:05 PM