Question Details

No question body available.

Tags

c# .net xml serialization dataset

Answers (1)

February 26, 2026 Score: 2 Rep: 79,784 Quality: Medium Completeness: 80%

Theoretically you could use a bunch of assembly bindings for the relevant types causing an issue, from the deserialization side. But the best bet might be to just chop off the assembly name from the type when serializing.

If you are able to control the serialization side, it's possible to modify the behaviour of the schema writer. Unfortunately this is not made available on the WriteXml function, only on the WriteXmlSchema function, so you need to build up the XML manually.

using (var xr = XmlWriter.Create(yourStreamWriter, new XmlWriterSettings { Indent = true }))
{
    xr.WriteStartDocument();
    xr.WriteStartElement(ds.DataSetName);
    ds.WriteXmlSchema(xr,
        // if the type code is Object (so not a basic type) and it's an mscorlib type
        t => Type.GetTypeCode(t) == TypeCode.Object && t.Assembly == typeof(string).Assembly
            ? t.FullName    // name without assembly
            : null);
    foreach (DataTable table in ds.Tables)
    {
        table.WriteXml(xr);
    }
    xr.WriteEndElement();
}

dotnetfiddle