I have to use an externally given xml structure (huge). I use the xsd tool of visual studio to generate classes that should be (de)serialized using xmlserializer. Since we switched from VS2010 to VS2012 (but still targeting .NET 4.0), I have problems deserializing the XML. I broke it down to the following code:
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute]
[System.Diagnostics.DebuggerStepThroughAttribute]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[XmlRootAttribute("DecoderParameter", Namespace = "", IsNullable = false)]
public class DecoderParameterType
{
private string[] decoderUpdatePointsField;
/// <remarks/>
[XmlAttributeAttribute(DataType = "integer")]
public string[] DecoderUpdatePoints
{
get
{
return this.decoderUpdatePointsField;
}
set
{
this.decoderUpdatePointsField = value;
}
}
}
[TestClass]
public class UnitTest1
{
#region Public Methods and Operators
[TestMethod]
public void TestMethod1()
{
var fileName = "c:\\temp\\test.xml";
var deserializer = new XmlSerializer(typeof(DecoderParameterType));
var output = new DecoderParameterType { DecoderUpdatePoints = new[] { "5", "7", "9" } };
using (var fs = new FileStream(fileName, FileMode.Create))
{
deserializer.Serialize(fs, output);
}
using (var sr = new XmlTextReader(fileName))
{
var myParameter = (DecoderParameterType)deserializer.Deserialize(sr);
}
}
#endregion
}
This code snippet fails with an Exception:
System.Xml.XmlException: 'None' is an invalid XmlNodeType.
It works if I remove "DataType = integer" from the XmlAttributeAttribute.
Now I have the following questions:
- Why does installing .NET4.5 change the behaviour of a .NET4.0 - program? Or is this not the case and I am missing something? (Before I installed VS2012, this worked fine! Now it is neither in VS2010 nor in VS2012 working)
- What side effects has the removal of the datatype declaration?
- Which other datatype declarations are also affected? I have a lot of these declarations in the generated code, not only integer (nonNegativeInteger, date, etc...).
Update: The problem occurs only if the variable is an array.
Kind regards