Monday, June 1, 2026

Don't just "Trim unused code"

Trimming unused code works great in NET Core.

Until it doesn't.

An example:

  • integration library with multiple DataContract/DataMember models for Core.WCF
  • "Trim unused code" trims away setters as it considers setters are not used
  • WCF initializer throws InvalidDataContractException: No get method for property 'Foo' in type 'Bar'
  • 3 hours wasted on debugging this

Yes, you can possibly add some code to a list of trimmer exceptions. And yes, you have to know that the trimmer is the culprit, in the first place.