Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Native AOT publish of a consumer reports trim/AOT warnings inside BLite.Core: `#pragma warning disable IL2026/IL3050/IL2070` hides reflection from BLite's build but not from ILC

Open
#275 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active

Research direction

Start with the pragma sites listed under src/BLite.Core and the emitted calls in src/BLite.SourceGenerators/MapperGenerator.cs. Run tools/aot-smoke/run.sh to reproduce consumer and Consumer.Linq warnings, then compare AOT_LIMITATIONS.md with the annotated APIs. Done means ILC no longer reports the covered internal/generated sites, expected consumer call-site warnings remain, runtime smoke checks pass, and documented limitations match the final annotations.

Written by the indexing model from the issue text.

Description

bug package/core severity/low

Summary

A consumer that publishes with Native AOT and uses only the APIs AOT_LIMITATIONS.md calls safe still gets trim/AOT warnings attributed to BLite.Core and to the code BLite's source generator emits into the consumer. BLite.Core silences the trim and AOT analyzers with #pragma warning disable IL2026 / IL3050 / IL2070 ... around reflection and Expression.Compile() instead of annotating or restructuring the code. The pragma satisfies the library's own build, which is the check AOT_LIMITATIONS.md relies on, but it is a Roslyn directive: ILC analyses the IL again in the consumer's publish and reports every one of those sites there.

The promise that annotated APIs warn at the call site holds. What breaks is the promise that nothing else warns.

The pragma sites

git grep -n 'pragma warning disable IL' -- src/BLite.Core on 0450b97 (v5.2.3), 13 lines:

src/BLite.Core/Collections/BaseMappers.cs:37:#pragma warning disable IL2026
src/BLite.Core/Collections/BsonSchemaGenerator.cs:177:#pragma warning disable IL2070
src/BLite.Core/GDPR/PersonalDataResolver.cs:152:#pragma warning disable IL2026
src/BLite.Core/Metadata/ValueConverterRegistry.cs:20:#pragma warning disable IL3050, IL2026
src/BLite.Core/Query/BTreeExpressionVisitor.cs:4:#pragma warning disable IL3050
src/BLite.Core/Query/BTreeQueryProvider.cs:30:#pragma warning disable IL3050, IL2026, IL2075
src/BLite.Core/Query/BTreeQueryProvider.cs:81:#pragma warning disable IL3050, IL2026
src/BLite.Core/Query/BTreeQueryable.cs:5:#pragma warning disable IL3050, IL2026
src/BLite.Core/Query/BsonExpressionEvaluator.cs:4:#pragma warning disable IL3050
src/BLite.Core/Query/BsonExpressionEvaluator.cs:736:#pragma warning disable IL2070, IL2075
src/BLite.Core/Query/BsonProjectionCompiler.cs:7:#pragma warning disable IL3050, IL2026, IL2072
src/BLite.Core/Query/EnumerableRewriter.cs:12:#pragma warning disable IL2026
src/BLite.Core/Query/EnumerableRewriter.cs:51:#pragma warning disable IL3050, IL2026, IL2060, IL2072

(src/BLite.SourceGenerators emits further pragmas into generated code for the private-setter fallback, which AOT_LIMITATIONS.md documents; those are not part of this issue.) The BaseMappers.cs site is the one behind the functional failure in #273 and is tracked there.

What a consumer's publish reports

tools/aot-smoke/run.sh, osx-arm64, .NET SDK 10.0.401, ILCompiler 10.0.12, TrimmerSingleWarn=false so every warning is itemised:

Consumer publish warnings by assembly: BLite.Caching=4, BLite.Core=4, BLite.SourceGenerators (generated into the consumer)=2 (total 10)
Consumer.Linq additional warnings by assembly: BLite.Core=11 (total 11)

The Consumer uses only the safe APIs plus the dynamic collection and the key-value store. Of its 10: 2 are A1 (UsedKeys), 4 are BLite.Caching (#276), and the 4 below are this issue. Consumer.Linq adds one AsQueryable().Where(...), one CreateIndexAsync and one typed Watch; its 11 extra warnings are all inside BLite.Core.

1. Every source-generated DbContext warns in its generated code (2 in the Consumer publish)
.../AotSmoke.AotDbContext_Model.Mappers.g.cs(190): AOT analysis warning IL3050: AotSmoke.AotDbContext.InitializeCollections():
  Using member 'BLite.Core.DocumentDbContext.CreateCollection<Int32,StoreDoc>(IDocumentMapper`2<Int32,StoreDoc>)' which has 'RequiresDynamicCodeAttribute' ...
.../AotSmoke.AotDbContext_Model.Mappers.g.cs(190): Trim analysis warning IL2026: ... the same member ...

DocumentDbContext.CreateCollection and CreateSessionCollection carry [RequiresDynamicCode]/[RequiresUnreferencedCode] (src/BLite.Core/DocumentDbContext.cs:291-292, :431-432) because a model may declare value converters or key selectors that compile expressions. The generator emits the calls in InitializeCollections() and Set<TId, T>() (src/BLite.SourceGenerators/MapperGenerator.cs:201, :206, :282) without annotation, so the warning lands in a file the consumer cannot edit. At runtime the warned path works under AOT for a model with two HasIndex and no converter (the 300-step sequence passes), so the annotation is broader than the risk, which is a property of the model, not of creating a collection.

2. ValueConverterRegistry.Empty (2 in the Consumer publish)
src/BLite.Core/Metadata/ValueConverterRegistry.cs(21): AOT analysis warning IL3050: BLite.Core.Metadata.ValueConverterRegistry..cctor():
  Using member 'ValueConverterRegistry.ValueConverterRegistry(Dictionary`2<String,Type>)' which has 'RequiresDynamicCodeAttribute' ...
src/BLite.Core/Metadata/ValueConverterRegistry.cs(21): Trim analysis warning IL2026: ... the same ...

public static readonly ValueConverterRegistry Empty = new(new Dictionary<string, Type>()); (:20-22) calls the annotated constructor with an empty dictionary, which never reaches Expression.Compile(). Harmless at runtime; ILC cannot see the loop is empty.

3. LINQ provider internals (10 of the 11 Consumer.Linq extras)
src/BLite.Core/Query/BTreeQueryProvider.cs(48): AOT analysis warning IL3050: BTreeQueryProvider`2.<>c.<CreateQuery>b__3_0(Type): Using member 'MethodInfo.MakeGenericMethod(Type[])' ...
src/BLite.Core/Query/BTreeQueryProvider.cs(95): AOT analysis warning IL3050: BTreeQueryProvider`2.<>c__DisplayClass9_0`1.<Execute>b__0(): ...
src/BLite.Core/Query/BTreeQueryable.cs(526): AOT analysis warning IL3050: BTreeQueryable`1.<GetAsyncEnumerator>d__60.MoveNext(): ...
src/BLite.Core/Query/EnumerableRewriter.cs(89): AOT analysis warning IL3050 / Trim analysis warning IL2060: EnumerableRewriter.VisitMethodCall(...): MakeGenericMethod ...
src/BLite.Core/Query/BsonExpressionEvaluator.cs(814): AOT analysis warning IL3050: BsonExpressionEvaluator.TryEvaluate(Expression): Expression.Lambda ...
src/BLite.Core/Query/BsonExpressionEvaluator.cs(739): Trim analysis warning IL2070: BsonExpressionEvaluator.HasFieldInHierarchy(Type,String): ...
src/BLite.Core/Query/BTreeExpressionVisitor.cs(114): AOT analysis warning IL3050: BTreeExpressionVisitor.AddPredicate(LambdaExpression): Expression.Lambda ...

The IQueryProvider/IAsyncEnumerable members implement interfaces that are not annotated, so they cannot carry [RequiresDynamicCode] without IL2046; the files use pragmas instead. The user already gets the call-site warning on AsQueryable, so these are noise in a library assembly. The BsonExpressionEvaluator fallback (Expression.Lambda(expression).Compile().DynamicInvoke(), :814-815) is the one AOT-suspect spot on a query's evaluation path and may deserve its own decision (#50 moved most of that path to interpretation).

4. Typed Watch is annotated but not documented (1 of the 11)
src/BLite.Core/GDPR/PersonalDataResolver.cs(153): Trim analysis warning IL2026: BLite.Core.GDPR.PersonalDataResolver.ReferencesOrIsAssembly(Assembly,Assembly):
  Using member 'System.Reflection.Assembly.GetReferencedAssemblies()' ...

DocumentCollection<TId, T>.Watch(WatchOptions?) and Watch(bool) carry [RequiresUnreferencedCode("Watch resolves personal-data fields via PersonalDataResolver which uses reflection.")] (src/BLite.Core/Collections/DocumentCollection.cs:4578, :4634), and the call site warns as it should, but AOT_LIMITATIONS.md lists LINQ, index creation, schema generation and value converters only. The other GDPR entry points (GdprEngineExtensions, GdprDocumentDbContextExtensions, PersonalDataMetadataCache) are annotated and undocumented too. The dynamic DynamicCollection.Watch is unannotated and passes under AOT (66 events identical in both builds).

Which promise each breaks

AOT_LIMITATIONS.md on main:

  • Overview point 1 (lines 9-12): "users receive specific, actionable warnings at their call sites rather than the vague rollup warnings". All 4 + 11 warnings above are inside BLite.Core or generated code, none at a consumer call site.
  • Overview point 2 (lines 13-14): "BLite.Core's own build validates annotations via the EnableAotAnalyzer and EnableTrimAnalyzer properties". It validates them only where no pragma turned it off.
  • Summary table line 157: "Generated mapper (no private setters) ✅ Yes, fully safe path": the generated context warns (section 1).
  • "Annotated (AOT-unfriendly) APIs" (lines 18-97): typed Watch and the GDPR APIs are annotated and missing (section 4).

What holds

Every annotated API the smoke test calls warns at its own line with the expected codes: AsQueryable IL2026 + IL3050, CreateIndexAsync IL3050, typed Watch IL2026. Outside the registered candidates the JIT and Native AOT dumps are byte-identical (871 lines: the typed store sequence, encrypted marker/reopen, dynamic collection with CDC and BLQL, key-value store).

Affected versions

Since 9fdae7c (#47, v4.2.0) for the annotations and pragmas; ValueConverterRegistry.Empty exists since v3.1.0. Up to v5.2.3.

Fix direction

Your call on the shape per site; the common thread is to replace the pragma with something ILC sees:

  • [UnconditionalSuppressMessage] with a justification where the only entry is an annotated API (the LINQ internals: "reachable only through AsQueryable, which carries RequiresDynamicCode"); unlike #pragma, it travels in the IL;
  • restructure where nothing dynamic happens (ValueConverterRegistry.Empty: a private constructor that only creates the empty dictionary);
  • annotate the generated InitializeCollections/Set, or narrow CreateCollection's annotation to the parts that compile expressions;
  • add typed Watch and the GDPR APIs to AOT_LIMITATIONS.md, with DynamicCollection.Watch as the AOT-safe alternative.

found by tools/aot-smoke in #277

Related: #45, #47, #50, #273, #276

Dominant language
C#
Stars
66
Forks
6
Avg merge
1d 2h
Merged PRs (30d)
58

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from EntglDb/BLite

All issues in EntglDb/BLite

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.