gpt4 book ai didi

c# - WCF CultureInfo 类型化 DataMember 序列化 CommunicationException

转载 作者:太空宇宙 更新时间:2023-11-03 20:05:39 25 4
gpt4 key购买 nike

当我使用 CultureInfo Typed DataMember 调用我的 WCF 服务的方法时,它抛出 CommunicationException。

我该如何解决这个问题?

The InnerException message was 'Type 'System.Globalization.GregorianCalendar' with data contract name 'GregorianCalendar:http://schemas.datacontract.org/2004/07/System.Globalization' is not expected. Add any types not known statically to the list of known types

[DataContract]
class MyClass
{
[DataMember]
public CultureInfo UserCulture { get; set; }
}

最佳答案

将此配置添加到主机和客户端配置。

<system.runtime.serialization>
<dataContractSerializer>
<declaredTypes>
<add type="System.Globalization.CultureInfo, mscorlib,Version=2.0.0.0, Culture = neutral, PublicKeyToken=b77a5c561934e089">
<knownType type="System.Globalization.GregorianCalendar,mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</add>
</declaredTypes>
</dataContractSerializer>

CultureInfo contains a calendar field of the base class Calendar and it doesn't know about the specialized GregorianCalendar type, but we would expect that's taken care of by adding the knowntype attribute.

http://www.vistax64.com/indigo/65776-cultureinfo-serialization-issue-gregoriancalendar-wcf.html

关于c# - WCF CultureInfo 类型化 DataMember 序列化 CommunicationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23633923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com