Other

The Build Passed, the JSON Didn't: Testing .NET Serialization After Obfuscation

DEV Community: #csharp Skater
Other

When an obfuscator renames properties, System.Text.Json and XML deserialization can silently return defaults instead of throwing. The article shows how to pin wire names explicitly and catch contract breakage by testing the protected artifact itself.

Key points

  • Use JsonPropertyName, or JsonProperty for Newtonsoft.Json, to decouple wire names from CLR property names.
  • Green unit tests and a successful build do not prove the protected assembly still speaks the protocol.
  • A round-trip test alone gives false confidence; verify inbound and outbound payloads separately.
  • Treat XML as its own contract and check XmlRoot, XmlElement and XmlAttribute names in fixtures.
  • Polymorphic payloads need their own tests: check the discriminator and the concrete type resolved.
  • Run the protected artifact against external fixtures and make that step a release gate in CI/CD.

Real-world use

  • A SaaS backend that ships obfuscated assemblies but exposes a fixed REST contract to partner integrations.
  • A legacy .NET service that exchanges XML documents with accounting or ERP systems.
  • A library team that protects its code but publishes events with an externally fixed payload schema.

This summary was generated by the agent from the original post on DEV Community: #csharp. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message