Question

When I Call my WCF service's Method with CultureInfo Typed DataMember it throws CommunicationException.

How can I solve this?

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; } 
}
Was it helpful?

Solution

Add this configuration to both host and clients configs.

<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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top