0

I have the following XML to serialize:

<ArrayOfStockObject xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/LLL_server.Models">
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i1">
<G_ArticleType z:Id="i2" i:type="ArtTypeBall">
<G_Descr>Weißer Fussball!</G_Descr>
<G_Color>Weiß</G_Color>
<G_Material>Leder</G_Material>
<G_Radius>20</G_Radius>
</G_ArticleType>
<G_Code i:nil="true"/>
<G_Place i:nil="true"/>
<G_Position i:nil="true"/>
<G_StoredAt>0001-01-01T00:00:00</G_StoredAt>
</StockObject>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i3">
<G_ArticleType z:Id="i4" i:type="ArtTypeBall">
<G_Descr>Roter Gummiball!</G_Descr>
<G_Color>Rot</G_Color>
<G_Material>Gummi</G_Material>
<G_Radius>15</G_Radius>
</G_ArticleType>
<G_Code i:nil="true"/>
<G_Place i:nil="true"/>
<G_Position i:nil="true"/>
<G_StoredAt>0001-01-01T00:00:00</G_StoredAt>
</StockObject>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i5">
<G_ArticleType z:Id="i6" i:type="ArtTypeBall">
<G_Descr>Tischtennisball Orange!</G_Descr>
<G_Color>Orange</G_Color>
<G_Material>Plastik</G_Material>
<G_Radius>2</G_Radius>
</G_ArticleType>
<G_Code i:nil="true"/>
<G_Place i:nil="true"/>
<G_Position i:nil="true"/>
<G_StoredAt>0001-01-01T00:00:00</G_StoredAt>
</StockObject>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i7">
<G_ArticleType z:Id="i8" i:type="ArtTypeBall">
<G_Descr>Gelber Gummiball!</G_Descr>
<G_Color>Gelb</G_Color>
<G_Material>Gummi</G_Material>
<G_Radius>15</G_Radius>
</G_ArticleType>
<G_Code i:nil="true"/>
<G_Place i:nil="true"/>
<G_Position i:nil="true"/>
<G_StoredAt>0001-01-01T00:00:00</G_StoredAt>
</StockObject>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i9">
<G_ArticleType z:Id="i10" i:type="ArtTypeBall">
<G_Descr>Blauer Gummiball!</G_Descr>
<G_Color>Blau</G_Color>
<G_Material>Gummi</G_Material>
<G_Radius>15</G_Radius>
</G_ArticleType>
<G_Code i:nil="true"/>
<G_Place i:nil="true"/>
<G_Position i:nil="true"/>
<G_StoredAt>0001-01-01T00:00:00</G_StoredAt>
</StockObject>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i11">
<G_ArticleType z:Id="i12" i:type="ArtTypeLamp">
<G_Descr>Energiesparlampe</G_Descr>
<G_Power>20</G_Power>
</G_ArticleType>
<G_Code i:nil="true"/>
<G_Place i:nil="true"/>
<G_Position i:nil="true"/>
<G_StoredAt>0001-01-01T00:00:00</G_StoredAt>
</StockObject>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i13">
<G_ArticleType z:Id="i14" i:type="ArtTypeLamp">
<G_Descr>Helle Lampe</G_Descr>
<G_Power>100</G_Power>
</G_ArticleType>
<G_Code i:nil="true"/>
<G_Place i:nil="true"/>
<G_Position i:nil="true"/>
<G_StoredAt>0001-01-01T00:00:00</G_StoredAt>
</StockObject>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i15">
<G_ArticleType z:Ref="i2"/>
<G_Code i:nil="true"/>
<G_Place z:Id="i16">
<G_Name>Platz_1</G_Name>
<G_Stock z:Id="i17">
<G_PlaceList>
<Place z:Ref="i16"/>
<Place z:Id="i18">
<G_Name>Platz_2</G_Name>
<G_Stock z:Ref="i17"/>
</Place>
<Place z:Id="i19">
<G_Name>Platz_3</G_Name>
<G_Stock z:Ref="i17"/>
</Place>
<Place z:Id="i20">
<G_Name>Platz_4</G_Name>
<G_Stock z:Ref="i17"/>
</Place>
<Place z:Id="i21">
<G_Name>Platz_5</G_Name>
<G_Stock z:Ref="i17"/>
</Place>
<Place z:Id="i22">
<G_Name>Platz_6</G_Name>
<G_Stock z:Ref="i17"/>
</Place>
<Place z:Id="i23">
<G_Name>Platz_7</G_Name>
<G_Stock z:Ref="i17"/>
</Place>
<Place z:Id="i24">
<G_Name>Platz_8</G_Name>
<G_Stock z:Ref="i17"/>
</Place>
<Place z:Id="i25">
<G_Name>Platz_9</G_Name>
<G_Stock z:Ref="i17"/>
</Place>
<Place z:Id="i26">
<G_Name>Platz_10</G_Name>
<G_Stock z:Ref="i17"/>
</Place>
</G_PlaceList>
</G_Stock>
</G_Place>
<G_Position z:Id="i27">
<G_Code i:nil="true"/>
<G_ObjectList>
<StockObject z:Ref="i15"/>
<StockObject z:Id="i28">
<G_ArticleType z:Ref="i2"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i16"/>
<G_Position z:Ref="i27"/>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
</G_ObjectList>
<G_Order z:Id="i29">
<G_CompletelyPicked>false</G_CompletelyPicked>
<G_PositionList>
<Position z:Ref="i27"/>
<Position z:Id="i30">
<G_Code i:nil="true"/>
<G_ObjectList>
<StockObject z:Id="i31">
<G_ArticleType z:Ref="i4"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i18"/>
<G_Position z:Ref="i30"/>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
</G_ObjectList>
<G_Order z:Ref="i29"/>
<G_Picked>false</G_Picked>
</Position>
</G_PositionList>
</G_Order>
<G_Picked>false</G_Picked>
</G_Position>
<G_StoredAt>2018-06-03T15:24:46.1067244</G_StoredAt>
</StockObject>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Ref="i28"/>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Ref="i31"/>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i32">
<G_ArticleType z:Ref="i6"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i19"/>
<G_Position z:Id="i33">
<G_Code i:nil="true"/>
<G_ObjectList>
<StockObject z:Ref="i32"/>
</G_ObjectList>
<G_Order z:Id="i34">
<G_CompletelyPicked>false</G_CompletelyPicked>
<G_PositionList>
<Position z:Ref="i33"/>
<Position z:Id="i35">
<G_Code i:nil="true"/>
<G_ObjectList>
<StockObject z:Id="i36">
<G_ArticleType z:Ref="i12"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i20"/>
<G_Position z:Ref="i35"/>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
</G_ObjectList>
<G_Order z:Ref="i34"/>
<G_Picked>false</G_Picked>
</Position>
<Position z:Id="i37">
<G_Code i:nil="true"/>
<G_ObjectList>
<StockObject z:Id="i38">
<G_ArticleType z:Ref="i8"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i21"/>
<G_Position z:Ref="i37"/>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
</G_ObjectList>
<G_Order z:Ref="i34"/>
<G_Picked>false</G_Picked>
</Position>
</G_PositionList>
</G_Order>
<G_Picked>false</G_Picked>
</G_Position>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Ref="i36"/>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Ref="i38"/>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i39">
<G_ArticleType z:Ref="i10"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i21"/>
<G_Position z:Id="i40">
<G_Code i:nil="true"/>
<G_ObjectList>
<StockObject z:Ref="i39"/>
</G_ObjectList>
<G_Order z:Id="i41">
<G_CompletelyPicked>false</G_CompletelyPicked>
<G_PositionList>
<Position z:Ref="i40"/>
</G_PositionList>
</G_Order>
<G_Picked>false</G_Picked>
</G_Position>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i42">
<G_ArticleType z:Ref="i12"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i21"/>
<G_Position z:Id="i43">
<G_Code i:nil="true"/>
<G_ObjectList>
<StockObject z:Ref="i42"/>
</G_ObjectList>
<G_Order z:Id="i44">
<G_CompletelyPicked>false</G_CompletelyPicked>
<G_PositionList>
<Position z:Ref="i43"/>
<Position z:Id="i45">
<G_Code i:nil="true"/>
<G_ObjectList>
<StockObject z:Id="i46">
<G_ArticleType z:Ref="i8"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i22"/>
<G_Position z:Ref="i45"/>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
</G_ObjectList>
<G_Order z:Ref="i44"/>
<G_Picked>false</G_Picked>
</Position>
<Position z:Id="i47">
<G_Code i:nil="true"/>
<G_ObjectList>
<StockObject z:Id="i48">
<G_ArticleType z:Ref="i12"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i23"/>
<G_Position z:Ref="i47"/>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
</G_ObjectList>
<G_Order z:Ref="i44"/>
<G_Picked>false</G_Picked>
</Position>
</G_PositionList>
</G_Order>
<G_Picked>false</G_Picked>
</G_Position>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Ref="i46"/>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Ref="i48"/>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Id="i49">
<G_ArticleType z:Ref="i6"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i24"/>
<G_Position z:Id="i50">
<G_Code i:nil="true"/>
<G_ObjectList>
<StockObject z:Ref="i49"/>
</G_ObjectList>
<G_Order z:Id="i51">
<G_CompletelyPicked>false</G_CompletelyPicked>
<G_PositionList>
<Position z:Ref="i50"/>
<Position z:Id="i52">
<G_Code i:nil="true"/>
<G_ObjectList>
<StockObject z:Id="i53">
<G_ArticleType z:Ref="i4"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i25"/>
<G_Position z:Ref="i52"/>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
</G_ObjectList>
<G_Order z:Ref="i51"/>
<G_Picked>false</G_Picked>
</Position>
<Position z:Id="i54">
<G_Code i:nil="true"/>
<G_ObjectList>
<StockObject z:Id="i55">
<G_ArticleType z:Ref="i14"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i26"/>
<G_Position z:Ref="i54"/>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
<StockObject z:Id="i56">
<G_ArticleType z:Ref="i14"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i26"/>
<G_Position z:Ref="i54"/>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
<StockObject z:Id="i57">
<G_ArticleType z:Ref="i14"/>
<G_Code i:nil="true"/>
<G_Place z:Ref="i26"/>
<G_Position z:Ref="i54"/>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
</G_ObjectList>
<G_Order z:Ref="i51"/>
<G_Picked>false</G_Picked>
</Position>
</G_PositionList>
</G_Order>
<G_Picked>false</G_Picked>
</G_Position>
<G_StoredAt>2018-06-03T15:24:46.1077238</G_StoredAt>
</StockObject>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Ref="i53"/>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Ref="i55"/>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Ref="i56"/>
<StockObject xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" z:Ref="i57"/>
</ArrayOfStockObject>

and the following classes to create:

[XmlRoot(ElementName = "G_ArticleType", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class G_ArticleType
{
    [XmlElement(ElementName = "G_Descr", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public string G_Descr { get; set; }
    [XmlElement(ElementName = "G_Color", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public string G_Color { get; set; }
    [XmlElement(ElementName = "G_Material", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public string G_Material { get; set; }
    [XmlElement(ElementName = "G_Radius", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public string G_Radius { get; set; }
    [XmlAttribute(AttributeName = "Id", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Id { get; set; }
    [XmlAttribute(AttributeName = "type", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
    public string Type { get; set; }
    [XmlElement(ElementName = "G_Power", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public string G_Power { get; set; }
    [XmlAttribute(AttributeName = "Ref", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Ref { get; set; }
}

[XmlRoot(ElementName = "G_Code", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class G_Code
{
    [XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
    public string Nil { get; set; }
}

[XmlRoot(ElementName = "G_Place", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class G_Place
{
    [XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
    public string Nil { get; set; }
    [XmlElement(ElementName = "G_Name", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public string G_Name { get; set; }
    [XmlElement(ElementName = "G_Stock", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_Stock G_Stock { get; set; }
    [XmlAttribute(AttributeName = "Id", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Id { get; set; }
    [XmlAttribute(AttributeName = "Ref", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Ref { get; set; }
}

[XmlRoot(ElementName = "G_Position", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class G_Position
{
    [XmlAttribute(AttributeName = "nil", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
    public string Nil { get; set; }
    [XmlElement(ElementName = "G_Code", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_Code G_Code { get; set; }
    [XmlElement(ElementName = "G_ObjectList", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_ObjectList G_ObjectList { get; set; }
    [XmlElement(ElementName = "G_Order", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_Order G_Order { get; set; }
    [XmlElement(ElementName = "G_Picked", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public string G_Picked { get; set; }
    [XmlAttribute(AttributeName = "Id", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Id { get; set; }
}

[XmlRoot(ElementName = "StockObject", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class StockObject
{
    [XmlElement(ElementName = "G_ArticleType", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_ArticleType G_ArticleType { get; set; }
    [XmlElement(ElementName = "G_Code", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_Code G_Code { get; set; }
    [XmlElement(ElementName = "G_Place", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_Place G_Place { get; set; }
    [XmlElement(ElementName = "G_Position", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_Position G_Position { get; set; }
    [XmlElement(ElementName = "G_StoredAt", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public string G_StoredAt { get; set; }
    [XmlAttribute(AttributeName = "Id", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Id { get; set; }
    [XmlAttribute(AttributeName = "z", Namespace = "http://www.w3.org/2000/xmlns/")]
    public string Z { get; set; }
    [XmlAttribute(AttributeName = "Ref", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Ref { get; set; }
}

[XmlRoot(ElementName = "Place", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class Place
{
    [XmlAttribute(AttributeName = "Ref", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Ref { get; set; }
    [XmlElement(ElementName = "G_Name", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public string G_Name { get; set; }
    [XmlElement(ElementName = "G_Stock", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_Stock G_Stock { get; set; }
    [XmlAttribute(AttributeName = "Id", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Id { get; set; }
}

[XmlRoot(ElementName = "G_Stock", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class G_Stock
{
    [XmlAttribute(AttributeName = "Ref", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Ref { get; set; }
}

[XmlRoot(ElementName = "G_PlaceList", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class G_PlaceList
{
    [XmlElement(ElementName = "Place", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public List<Place> Place { get; set; }
}

[XmlRoot(ElementName = "G_ObjectList", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class G_ObjectList
{
    [XmlElement(ElementName = "StockObject", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public List<StockObject> StockObject { get; set; }
}

[XmlRoot(ElementName = "Position", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class Position
{
    [XmlAttribute(AttributeName = "Ref", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Ref { get; set; }
    [XmlElement(ElementName = "G_Code", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_Code G_Code { get; set; }
    [XmlElement(ElementName = "G_ObjectList", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_ObjectList G_ObjectList { get; set; }
    [XmlElement(ElementName = "G_Order", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_Order G_Order { get; set; }
    [XmlElement(ElementName = "G_Picked", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public string G_Picked { get; set; }
    [XmlAttribute(AttributeName = "Id", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Id { get; set; }
}

[XmlRoot(ElementName = "G_Order", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class G_Order
{
    [XmlAttribute(AttributeName = "Ref", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Ref { get; set; }
    [XmlElement(ElementName = "G_CompletelyPicked", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public string G_CompletelyPicked { get; set; }
    [XmlElement(ElementName = "G_PositionList", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public G_PositionList G_PositionList { get; set; }
    [XmlAttribute(AttributeName = "Id", Namespace = "http://schemas.microsoft.com/2003/10/Serialization/")]
    public string Id { get; set; }
}

[XmlRoot(ElementName = "G_PositionList", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class G_PositionList
{
    [XmlElement(ElementName = "Position", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public List<Position> Position { get; set; }
}

[XmlRoot(ElementName = "ArrayOfStockObject", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
public class ArrayOfStockObject
{
    [XmlElement(ElementName = "StockObject", Namespace = "http://schemas.datacontract.org/2004/07/LLL_server.Models")]
    public List<StockObject> StockObject { get; set; }
    [XmlAttribute(AttributeName = "i", Namespace = "http://www.w3.org/2000/xmlns/")]
    public string I { get; set; }
    [XmlAttribute(AttributeName = "xmlns")]
    public string Xmlns { get; set; }
}

I have generated them with http://xmltocsharp.azurewebsites.net/.

When I try to deserialize it with XmlSerializer, I get the following error:

There is an error in XML document (1, 225). ---> System.InvalidOperationException: The specified type was not recognized: name at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderArrayOfStockObject.Read2_G_ArticleType(Boolean isNullable, Boolean checkType)

I know there is something wrong with the ArticleType, but I just can`t see what. There is nothing missing after "type" in the error message. It is the exact message I get. Does anyone have an answer?

Greetings, Robert

  • I don't see any definition for `i:type="ArtTypeBall"`, your xml is not complete. Is there a schema file (*.xsd) somewhere? – H H Jun 09 '18 at 20:14
  • You can snip all but 2 of the s, but if there are any lines above this, post them. – H H Jun 09 '18 at 20:16
  • Yes I now also think i:type="ArtTypeBall" is the Problem. It has to do with inheritence. ArticleType has to subclasses on the serverside where it is serialized. I will google how to deserialize inheritance. If I get questions, I will post them here. – Robert Arnold Jun 09 '18 at 20:49
  • Agree with Henk that `ArtTypeBall` is missing, and also `ArtTypeLamp`. If I exclude all of those objects I get an array of 15 objects. And if I just remove the ` i:type="ArtTypeBall"` (and ...Lamp) from the XML, I get an array of 22 items. Have you looked in the InnerException property of the Exception that you're getting? Since it worked for me, I'm guessing it could be something like the encoding of your XML file. Check that the encoding is UTF8. – Richardissimo Jun 09 '18 at 20:53
  • It took me that long to write the comment, I didn't see Robert's comment... but that explains it. – Richardissimo Jun 09 '18 at 20:55
  • I found a solution for deserializing inheritence with XMLSerializer, but i run into another problem. I want to (de-)serialize while preserving references. I didn't find a solution for XMLSerializer so I changed on both (server and client) from XMLSerializer to Json.Net. But I run into another exception which I posted here: https://stackoverflow.com/questions/50787805/error-while-deserializing-with-json-net sry for my bad english – Robert Arnold Jun 10 '18 at 20:45

0 Answers0