DateTimeOffsetAdapter 干扰 DateTimeOffset 对象的 WCF 序列化

发布于 2024-07-25 17:26:09 字数 678 浏览 8 评论 0原文

我有一个由 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最终幸福 2024-08-01 17:26:10

就我而言,问题似乎源于在将 IIS 作为一项功能添加到 Windows 7 之前安装了 .Net 4。

我和一位同事通过打开提升的(以管理员身份运行)命令提示符解决了该问题。 然后运行以下内容:

cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319
aspnet_regiis.exe -i

希望这对某人有帮助!

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:

cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319
aspnet_regiis.exe -i

Hope this helps someone!

傻比既视感 2024-08-01 17:26:10

我不知道为什么。 但要解决该问题,请尝试将项目迁移到 .NET Framework 版本 4

I don't know why. But to solve the problem try to migrate your project to .NET Framework version 4

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文