Skip to content

XML Serialization in C#: retarget to .NET 10 and run the examples from Program.cs - #2281

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/62427-csharp-xml-serialization
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/62427-csharp-xml-serialization

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Updates the sample for the article "C# XML Serialization: Serialize Objects With XmlSerializer" (https://code-maze.com/csharp-xml-serialization/).

Changes, all inside xml-csharp/XMLSerializationInCsharp:

  • Both projects move from net5.0 to net10.0.
  • Program.cs printed "hello world". It now uses top-level statements to serialize one Patient twice and print both documents: once with a StreamWriter (the article's first example) and once with an XmlWriter using XmlWriterSettings (indentation, UTF-8 without a byte order mark) and an empty XmlSerializerNamespaces, so the root element has no xmlns:xsi or xmlns:xsd (the article's new last section).
  • New test XMLSerializationUnitTest_v6 checks that second example: no byte order mark, no namespace declarations, and the expected document with an encoding="utf-8" declaration.
  • The five existing test classes are unchanged. Their Assert.AreEqual calls compile and pass on NUnit 5.0.0.

Package versions, looked up on NuGet on 2026-10-10 (latest stable):

  • Microsoft.NET.Test.Sdk 18.10.1 (was 16.9.4)
  • NUnit 5.0.0 (was 3.13.1)
  • NUnit3TestAdapter 6.3.1 (was 3.17.0)
  • coverlet.collector 10.1.0 (was 3.0.2)

Local results on SDK 10.0.302 / runtime 10.0.10: dotnet build -c Release 0 warnings, 0 errors; dotnet test 7 passed, 0 failed; dotnet list package --vulnerable --include-transitive reports no vulnerable packages in either project.

…amples from Program.cs

Both projects move from net5.0 to net10.0. Test packages: Microsoft.NET.Test.Sdk 18.10.1,
NUnit 5.0.0, NUnit3TestAdapter 6.3.1, coverlet.collector 10.1.0.

Program.cs now serializes one Patient with a StreamWriter and with an XmlWriter
(indentation, UTF-8 without a byte order mark, no xmlns:xsi or xmlns:xsd) and prints both
documents, instead of printing hello world.

New test XMLSerializationUnitTest_v6 covers the XmlWriterSettings and empty
XmlSerializerNamespaces example the article adds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant