OPCFoundation / UA-.NETStandard

OPC Unified Architecture .NET Standard
Other
1.97k stars 948 forks source link

XmlSerializer in .NET 6 Omits LIne Breaks by Default #1759

Closed opcfoundation-org closed 2 years ago

opcfoundation-org commented 2 years ago

Type of issue

Current Behavior

UANodeSet.Write(Stream istrm) writes a NodeSet to disk without line breaks.

Expected Behavior

No response

Steps To Reproduce

No response

Environment

- OS:
- Environment:
- Runtime:
- Nuget Version:
- Component:
- Server:
- Client:

Anything else?

Fix:

public void Write(Stream istrm)
{
    XmlWriterSettings settings = new XmlWriterSettings() {
        Indent = true,
        Encoding = Encoding.UTF8,
        IndentChars = "    "
    };

    var writer = XmlWriter.Create(istrm, settings);

    try
    {
        XmlSerializer serializer = new XmlSerializer(typeof(UANodeSet));
        serializer.Serialize(writer, this, null);
    }
    finally
    {
        writer.Flush();
        writer.Dispose();
    }
}

See https://github.com/dotnet/runtime/issues/64885

mregen commented 2 years ago

Hi @opcfoundation-org, just in time for march roll up... thanks for the info!