all groups > dotnet xml > february 2007 >
You're in the

dotnet xml

group:

Serializing CultureInfo


Serializing CultureInfo Nahom Tijnam
2/11/2007 1:26:11 AM
dotnet xml:
Hi,

I have a class which has a property of type System.Globalisation.CultureInfo
in a class library project based on .NET framework 1.1 (Visual Studio 2003).

I want to expose the classes and its functionalities using Web Service but
while testing the web service, it throws the following error:
"System.Globalization.CultureInfo cannot be serialized because it does not
have a default public constructor."

Could someone please advise how I could solve this?
Thanks,

--
Nahom Tijnam
Re: Serializing CultureInfo Keith Patrick
2/12/2007 9:43:26 AM
Odd...I would have figured that this would have worked:
[TypeConverter(typeof(CultureInfoConverter))]

But the exception still occurs. Maybe someone can shed some light on why the
converter doesn't work (I've used Font and ColorConverters a lot with no
deserialization issues, so I'm a bit confused as to the problem with the
above)
Other than that, you can always fall back to the somewhat inelegant solution
of declaring your property as type CultureInfoWrapper & supply that type
with a default ctor.

Re: Serializing CultureInfo Keith Patrick
2/12/2007 9:48:56 AM
It just hit my why my Font/ColorConverter usage never caused this kind of
problem: I use a custom serializer (the built-in serializer has issues with
some classes that implement interfaces, those that have no default ctors,
etc.)
So, another option is to write your own serializer (they're not that
difficult, really)

Once my coffee kicks in, something else might pop into my head...primarily
in the area of one of the Xml*Attributes that might clue the serializer into
looking for TypeConverter attributes.

AddThis Social Bookmark Button