IgniteUI.Blazor.Lite — Trimming
The library ships IsTrimmable and must stay trim-clean: every trim-analysis diagnostic (IL2xxx) builds as an error, enforced by dotnet_analyzer_diagnostic.category-Trimming.severity = error in the repo .editorconfig. The source of truth for policy and consumer guidance is docs/TRIMMING.md — read its "Maintaining trim compatibility (contributors)" section before working around any IL2xxx error.
Rules
- Fix first. Serialize through source-generated
JsonTypeInfo— extendIgbJsonContext(src/componentsBase/IgbJsonContext.cs) rather than calling reflection-basedJsonSerializeroverloads. AnnotateTypeflows with[DynamicallyAccessedMembers]where the flow is traceable (scalarType/stringparameters, properties, generic parameters — annotations are invalid onType[]and do not trace through collections). For "keep members whenever the type is kept, however itsTypevalue flows" use the self-referencing generic attribute pattern:[IgbModule<TSelf>]on the module classes (seeIgbModuleAttribute<TModule>insrc/componentsBase/IgbModule.cs) — a new module MUST carry it, guarded byServiceRegistrationTests.EveryLibraryModule_CarriesSelfReferencingIgbModuleAttribute. - Never annotate method parameters or fields of component base classes (
BaseRendererControl,BaseRendererElement, or anything ComponentBase-derived).OpenComponent<T>roots component members "via reflection", so such annotations surface as IL2111/IL2110 errors in every consuming app. Annotated properties are fine (framework precedent:RouteView.DefaultLayout). - Suppress narrowly when a fix is impossible.
[UnconditionalSuppressMessage("Trimming", "ILxxxx", Justification = "...")]on the smallest member, with a justification stating why the pattern is safe at runtime; extract a small private helper if needed so the justification matches exactly what the member does. Keep the helper'sTypeparameter unannotated — annotating it only moves the warning to the caller. - Never use
#pragma warning disablefor ILxxxx. It silences only the build analyzer and leaves no metadata for publish-time trim tooling (ILLink, NativeAOT's ILCompiler). - Don't add reflection over user-supplied or runtime-discovered types outside the documented data-source boundary (
JSDataSourceSchemaand theExtractSchemaentry points).
Verification
dotnet build src/IgniteUI.Blazor.Lite.csprojmust be free of IL diagnostics (they fail the build).- For changes touching reflection, serialization, or annotations, run the automated browser checks over the trimmed publish:
dotnet test tests/IgniteUI.Blazor.Lite.IntegrationTests --filter Category=TrimmedPublish --settings .runsettings(TrimmedPublishSmokeTest; publishes the smoke app net10.0 on demand). It is category-scoped — not part of the per-component integration sweep — and covers net10.0 only; the manual checklist intests/IgniteUI.Blazor.Lite.PublishSmoke/README.mdcovers the other TFMs. Trimming only happens at publish (dotnet runproves nothing). - Verify claims about linker behavior empirically in the smoke app — a control-vs-fix publish pair, not reasoning from documentation alone.