XmlSerializers ?
Can someone explain XmlSerializers to me?
I've run into an exception being thrown by some code I've inherited, Looks like a method is attempting to Serialize some assemblies and is failing because it cannot locate the XmlSerializers.dll versions of the assemblies, anyone any clue as to what could be happening and what these <assemblyname>.XmlSerializers.dll are all about!
This is the method that's throwing the exception when it cannot locate the XmlSerializers.dll
public static T LoadFromReader<T>(XmlReader reader)
{
XmlSerializer ser = new XmlSerializer(typeof(T));
return (T) ser.Deserialize(reader);
}
[697 byte] By [
ireland] at [2007-11-20 1:29:09]

# 1 Re: XmlSerializers ?
The XML Serializer Generator (Sgen.exe) creates an XML serialization assembly for types in a specified assembly in order to improve the startup performance of a XmlSerializer (http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx) when it serializes or deserializes objects of the specified types.
When the XML Serializer Generator is not used, a XmlSerializer (http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx) generates serialization code and a serialization assembly for each type every time an application is run. To improve the performance of XML serialization startup, use the Sgen.exe tool to generate those assemblies the assemblies in advance. These assemblies can then be deployed with the application.
If the assembly containing the type to serialize is named MyType.dll, then the associated serialization assembly will be named MyType.XmlSerializers.dll.
Details here (http://msdn2.microsoft.com/en-us/library/bk3w6240.aspx)
# 2 Re: XmlSerializers ?
Thanks Creatorul, I already had a look through the msdn.
What I do not understand is why it is serializing the assemblies, I read that it has something to do with webservices, what's the deal here? are any assemblies used by the webservice serialized ?
My code is looking unsuccessfully for the serialized version of an assembly so I've tried to create it manually first myself.
When I try to generate the serialized version of my assembly it fails with
C:\project\export\bin\debug\Tools>"C:\Program Files\Microsoft Visual Studi
o 8\SDK\v2.0\Bin\sgen.exe" /a:Assembly.dll
Microsoft (R) Xml Serialization support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation. All rights reserved.
Error: Unable to generate a temporary class (result=1).
error CS0272: The property or indexer 'Assembly.Location.Reference' cannot be used
in this context because the set accessor is inaccessible
error CS0272: The property or indexer 'Assembly.Location.Reference' cannot be used
in this context because the set accessor is inaccessible
If you would like more help, please type "sgen /?".
The assembly is made up of about 10 classes. Is there something I should set in the AssemblyInfo.cs or something?
# 3 Re: XmlSerializers ?
Ok so I see the cause of the Error, there is a properted setter on the Property Reference in the Location class
public virtual object Reference
{
get { return _reference; }
protected set { _reference = value; }
}
Is there anyway to ignore this?
I don't want to change this working code.