.NET 8 and Trimming
In .NET 6, trimming worked pretty well, even if your assemblies weren’t annotated properly. In .NET 7 and now with .NET 8, things have changed, and trying to trim with the same project files and settings will cause everything to break.
If you want to get the old .NET 6 behavior, annotate your csproj files with these elements:
<TrimMode>partial</TrimMode>
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
Hoping this saves someone the hours I lost fussing around with this. Microsoft’s trimming guide is good, but doesn’t mention the json property, which is now false by default in .NET 8, instead of true.
You are right sr.! It worked for me after 3 days. Microsoft does not mention that.
Glad I could save you some time 🙂