Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Indigo

CultureInfo Serialization Issue with GregorianCalendar in WCF

Update your Vista Drivers Update Your Drivers Now!!
 
 
Thread Tools Display Modes
Old 05-24-2007   #1 (permalink)
Willie Tu
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 SpecsSystem Spec
 

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


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51