I stumbled upon a problem with the .NET XmlSerializer.
Whenever I try to deserialize some of my projects classes I get an FileNotFound
-Exception with the following message:
Could not load file or assembly 'mscorlib.XmlSerializers, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies.
The system cannot find the file specified.
I know that I get that exception because I disabled the "Just My Code"-Option in the visual studio. I actually want to get that exception so I can make sure I generate an XmlSerializers.dll for the project that it's missing for, but as you can see in this case it's the mscorlib.dll. I can't seem to figure out what the problem is. When I use the sgen.exe and try to generate an XmlSerializers.dll for the project in which the class is that I am trying to deserialize I get some warnings, but the XmlSerializers.dll is generated. The class that is being deserialized has nothing special. It contains some properties of the following types
2x short
1x string
2x DateTime
1x List<short>
1x List<MyClass>
'MyClass' contains nothing special either, just some shorts, a string and one DateTime property.
I have other classes that basically have the same spectrum of datatypes and they deserialize just fine. Is this maybe a bug in the CLR?
I created a testproject and copied the 2 classes and deserialized them and got no exceptions.
My CLR Version is 2.0.
If you need more information on the subject let me know I would be glad to provide whatever you need if it helps me resolving this issue. Any help will be appreciated.
Thanks in advance.
Greetings,
Andre
Update:
Like sll requested here are the Classes
SerialzedClass:
public class SerializedClass
{
#region Constructor
/// <summary>
/// constructor for serialization only
/// </summary>
public SerializedClass() { }
/// <summary>
/// public constructor
/// </summary>
public SerializedClass(short id, string bez, DateTime updateY, DateTime updateX, short lastID)
{
this.ID = id;
this.Bez = bez;
this.UpdateY = updateY;
this.UpdateX = updateX;
this.LoadedSprs = new List<short>();
this.LoadedHandRefs = new List<TraderHandRef>();
this.LastID = lastID;
} // SerializedClass
#endregion
public short LastID { get; set; }
public short ID { get; set; }
public string Bez { get; set; }
public DateTime UpdateY { get; set; }
public DateTime UpdateX { get; set; }
public List<short> LanguageIDs { get; set; }
public List<MyClass> MyClass { get; set; }
}
MyClass:
public class MyClass
{
#region Constructor
/// <summary>
/// constructor for serialization only
/// </summary>
public MyClass() { }
#endregion
#region Properties
/// <summary>
/// get/set KID value
/// </summary>
public short KID { get; set; }
/// <summary>
/// get/set Date value
/// </summary>
public DateTime Date { get; set; }
/// <summary>
/// get/set VID value
/// </summary>
public short VID { get; set; }
/// <summary>
/// get/set description value
/// </summary>
public string Description { get; set; }
/// <summary>
/// get/set ID value
/// </summary>
public short ID { get; set; }
#endregion
}
My deserialize call looks like this:
System.Xml.Serialization.XmlSerializer serial = new System.Xml.Serialization.XmlSerializer(typeof(T));
where T represents SerializedClass.