Reputation: 16002
After installing studio 2012, building an application that targets framework 4.0. I am getting the error:
Type 'System.Threading.Tasks.Task' cannot be serialized.
Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with ....
I have regenerated the service reference using svcutil. Is there any way of specifying that all the asynchronous stuff is excluded from the reference?
?
Upvotes: 3
Views: 862
Reputation: 25601
I don't understand why, but it seems that in some build environments you need to add a switch /syncOnly
to the svcutil command line that generates the interface for your service after upgrading to Visual Studio 2012. The odd thing is, if I build and run locally on my desktop with Visual Studio 2012, I get all the async methods added to the interface and everything runs fine. But if I build on our separate build machine and run on a third machine, then I get errors like the one you have described. The error goes away when I add /syncOnly
to the command line as described at http://www.aspdotnethelp.com/a/d/type-system-threading-tasks-task1system-string-cannot-be-serialized-error-in-wcf-236.aspx
This causes the Async interface members not to be generated.
I have also seen the inclusion of async methods cause a different error:
Operations marked with IsOneWay=true must not declare output parameters, by-reference parameters or return values.
I suspect the cause revolves around using .NET 4.5 tools to build a .NET 4.0 application. Since the tools are generating code rather than compiling code, the version of .NET that they target is not enforced in the output. Then when you use code intended for .NET 4.5 in an application that targets .NET 4.0, some behaviors are out of sync.
Upvotes: 2
Reputation: 2181
As far as I know you can't use WCF task based asynchronous pattern on .NET 4.0 (you could but you need to install the Async Targeting Pack for Visual Studio 2012), you need to upgrade to .NET 4.5 to get it working.
I suspect that you were using some kind of extension (like the AsynCTP) on Visual Studo 2010.
Here you can see which asynchronous patterns are supported on each framework version:
Upvotes: 3