![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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 | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| XML Serialization | Tom | .NET General | 5 | 04-16-2008 02:30 PM |