Skip to content

TypeGen.Core.dll produces IL2104 trim warnings in any trimming-enabled .NET app #235

@Qythyx

Description

@Qythyx

Summary

When TypeGen is referenced from a library that is consumed by a .NET app
with trimming enabled (NativeAOT, MAUI, .NET for iOS/Android, Blazor
WebAssembly, or any app with <PublishTrimmed>true</PublishTrimmed>),
TypeGen.Core.dll produces an IL2104 trim-analysis warning:

/path/to/typegen/7.0.0/lib/net10.0/TypeGen.Core.dll : warning IL2104:
  Assembly 'TypeGen.Core' produced trim warnings.
  For more information see https://aka.ms/il2104

Repro

  1. Create a .NET 10 class library. Add <PackageReference Include="TypeGen" />.
  2. Decorate a type with [ExportTsInterface] (or any other TypeGen attribute).
  3. Reference this library from a project that has the trimmer enabled — any of:
    • a net10.0-ios / net10.0-android / MAUI project
    • a NativeAOT project (<PublishAot>true</PublishAot>)
    • a Blazor WebAssembly project
    • any project with <PublishTrimmed>true</PublishTrimmed>
  4. Build — the IL2104 warning is emitted.

Why it matters

Consumers of TypeGen use the package purely as a build-time code generator —
the dotnet-typegen CLI runs at build time, and the attributes
([ExportTsInterface], [TsMemberName], [TsIgnore], etc.) carry no runtime
behavior. But because attribute metadata references TypeGen.Core by fully
qualified name, the DLL still ships to consumers and gets trim-analyzed.

For any codebase adopting trimming (which is mandatory for NativeAOT and
default for mobile targets), this warning is noise that can't be cleanly
suppressed without broad <NoWarn> entries.

Possible fixes (in rough order of effort)

  1. Annotate TypeGen.Core as trim-safe — audit the internals, add
    [assembly: UnconditionalSuppressMessage] or
    [RequiresUnreferencedCode] / [RequiresDynamicCode] annotations where
    appropriate, and rebuild. This is the standard path library authors take
    (see Microsoft's guidance).

  2. Split the attributes into a separate, attribute-only assembly — e.g.
    TypeGen.Attributes that contains just the public attribute types and has
    no reflection or dynamic code. Consumers reference the thin attribute
    package at runtime; the heavier TypeGen.Core stays as a build-time
    tool-only dependency. This is a clean long-term design and what libraries
    like JetBrains.Annotations do.

  3. Mark the package as tool-only via IncludeAssets="build" /
    ExcludeAssets="runtime" in the package metadata — but this breaks the
    attribute-at-runtime use case, so only viable in combination with option 2.

Environment:

  • TypeGen 7.0.0
  • .NET 10 SDK

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions