Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - CultureInfo Serialization Issue with GregorianCalendar in WCF

 
 
Old 05-24-2007   #1 (permalink)
Willie Tu


 
 

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


Similar Threads
Thread Forum
Serialization optimization .NET General
XML Serialization .NET General


Vista Forums 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 Ltd

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