WCF XmlSerialization以某种方式错误解释为DataContract序列化 - 发布VS 2012 Update1

时间:2013-02-15 18:57:47

标签: wcf xml-serialization .net-4.5 datacontractserializer svcutil.exe

我们有一个WCF / ASP.NET托管的Web服务。服务合同中的数据类型使用XSD.exe生成的类型,因此使用XmlSerialization属性进行修饰。我们使用SvcUtil为它创建了一个客户端,包括使用/ser:XmlSerializer参数。已经工作了很多年。

我们刚刚升级了我们的构建脚本以使用VS 2012,以及VvA 8.0 V / Windows SDK NETFX 4.0工具版本的SvcUtil.exe(v 4.0.30319.17929)。

当我们的客户端(使用VS 2012和新的8.0A SvcUtil构建)尝试调用WCF服务时,我们现在看到一条奇怪的错误消息:

Type 'System.Threading.Tasks.Task1[MyNamespace.MyClient.MyDataStructure]' 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.

此错误阻止我们的应用程序能够调用WCF服务,而且我们被卡住了。

我注意到我们没有将参数传递给/async的SvcUtil。我还注意到.NET SDK 8.0A的SvcUtil帮助(v 4.0.30319.17929)表明默认为generate synchronous and task-based asynchronous method signatures. System.Threading.TaskXmlSerializer之间是否存在内置断开连接?

关于我们如何阻止运行时以某种方式认为我们在DataContractSerialization打算XmlSerialization时使用{{1}}的建议?

1 个答案:

答案 0 :(得分:1)

得到微软的回答,发布了here

简短的说法是,如果您打算使用.NET 4.5 /syncOnly进行构建但是以.NET 4运行时为目标,则需要SvcUtil