DateTimeOffsetAdapter 干扰 DateTimeOffset 对象的 WCF 序列化
我有一个由 Visual Studio 2008 (.net 3.5 sp1) 生成的 WCF 服务引用(= 客户端代理)。 生成的代码包含具有 DateTimeOffset 属性的数据协定,因此 VS 自然会用 KnowTypeAttribute(System.DateTimeOffset) 对其进行装饰。
每当我调用返回上述数据协定的 WCF 操作时,我都会收到以下异常:
不能输入“System.DateTimeOffset” 添加到已知类型列表中 另一种类型 'System.Runtime.Serialization.DateTimeOffsetAdapter' 具有相同的数据合约名称 'http://schemas.datacontract.org/2004/07/System:DateTimeOffset' 已经存在
我知道 DateTimeOffsetAdapter 是 System.Runtime.Serialization 中的一个结构,在序列化 DateTimeOffset 对象时使用。 那么为什么会导致此异常以及如何修复或避免此异常?
I have a WCF service reference (= client proxy) generated by Visual Studio 2008 (.net 3.5 sp1). The generated code contains a data contract with DateTimeOffset properties so naturally VS decorated it with KnowTypeAttribute(System.DateTimeOffset).
Whenever I invoke a WCF operation that returns the above mentioned data contract, I get the following exception:
Type 'System.DateTimeOffset' cannot be
added to list of known types since
another type
'System.Runtime.Serialization.DateTimeOffsetAdapter'
with the same data contract name
'http://schemas.datacontract.org/2004/07/System:DateTimeOffset'
is already present
I understand that DateTimeOffsetAdapter is a struct in System.Runtime.Serialization that is used when serializing DateTimeOffset objects. So why does it cause this exception and how can this be fixed or avoided?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我而言,问题似乎源于在将 IIS 作为一项功能添加到 Windows 7 之前安装了 .Net 4。
我和一位同事通过打开提升的(以管理员身份运行)命令提示符解决了该问题。 然后运行以下内容:
希望这对某人有帮助!
In my case the issue seemed to stem from having .Net 4 installed prior to adding IIS as a feature to Windows 7.
A colleague and I fixed the issue by opening an elevated (Run As Administrator) command prompt. Then ran the following:
Hope this helps someone!
我不知道为什么。 但要解决该问题,请尝试将项目迁移到 .NET Framework 版本 4
I don't know why. But to solve the problem try to migrate your project to .NET Framework version 4