Skip to content

[Code Quality] ServiceExporter.cs — XML export declares UTF-16 but file is written as UTF-8 #555

@Christophe-Rogiers

Description

@Christophe-Rogiers

Severity: Warning

File: src/Servy.Core/Services/ServiceExporter.cs, lines 32, 56

Description:
ExportXml uses StringWriter for XML serialization, which defaults to UTF-16. The serialized XML declaration reads <?xml version="1.0" encoding="utf-16"?>. However, File.WriteAllText(filePath, xmlString) writes the file as UTF-8 (default on .NET 5+).

A strict XML parser checking the declared encoding against the actual file encoding will reject the file.

Suggested fix:
Use XmlWriter with XmlWriterSettings { Encoding = new UTF8Encoding(false) } writing directly to a FileStream, so the declaration matches the actual encoding.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions