![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | CultureInfo Serialization Issue with GregorianCalendar in WCF Hi, We have a data contract of the following form: [DataContract] public class MyDataContract { [DataMember] IDictionary<CultureInfo, string> names; } We're able to set values into the "names" collection ok, but once DateTime.TryParse, DateTime.Parse, or DateTime.ToShortDateString() is called subsequent calls to the service utilizing the data contract would get the following exception: System.ServiceModel.CommunicationException: There was an error while trying to serialize parameter http://MyDataContract:names. 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 - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details. ---> System.Runtime.Serialization.SerializationException: 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 - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.. We have tried to explicitly add [KnownType(typeof(System.Globalization.GregorianCalendar))] attribute to the data contract but it doesn't change the proxy (generated by svcutil), and adding the attribute manually to the proxy doesn't get rid of the error as well. What worked is we had to add the following config to both the client and the service host config: <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> </system.runtime.serialization> Understandably, 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. We assumed since it is [Serializable] this is handled by the DataContractSerializer, and also it's part of the core system framework this should be handled. So we're confused why the requirement of this config on both the client and the service host? or our solution is incorrect and not addressing the actual problem? Thanks, Willie |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Serialization optimization | .NET General | |||
| XML Serialization | .NET General | |||