Skip to content

fix: report a type the generated container cannot name because another referenced assembly declares its full name (AWT260) - #455

Merged
vbreuss merged 11 commits into
mainfrom
fix/same-named-types-and-test-helper
Nov 15, 2026
Merged

vbreuss merged 11 commits into
mainfrom
fix/same-named-types-and-test-helper

Conversation

@vbreuss

@vbreuss vbreuss commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

When two referenced assemblies, or the project and a referenced assembly, declare an accessible type of the same full name, plain C# can name it only through an extern alias, which the generator cannot add. The generated container then failed with CS0433, CS0434 or a type mismatch instead of a diagnostic. The container now reports each such name once as AWT260, at the import, registration or Extends that brings it into the graph, and names the assemblies that declare it.

It covers every name the generated code spells: services, implementations, parameters, properties, imports, enum and typeof keys, async initializer types, deferred setters, and the modules and base containers the container calls into. A namespace of the same full name, or an accessible type named like one of its namespace segments, counts as a clash too. A reference with an extern alias stays out of global:: and is not reported, so the remedy offers an alias when the container needs nothing from that assembly, a reference to only one of the declarers, or a rename, and only a rename when the project declares the name itself.

The compilation-reference test helpers referenced the generated library without checking that it compiles, so a broken library build could pass in that mode while the emitted-assembly helpers already threw on it. They now fail with the library's errors.

@vbreuss vbreuss self-assigned this Nov 15, 2026
@vbreuss vbreuss added the bug Something isn't working label Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Test Results

    27 files  +    6      27 suites  +6   3h 11m 24s ⏱️ + 1h 45m 20s
 5 967 tests +1 610   5 967 ✅ +1 610  0 💤 ±0  0 ❌ ±0 
21 980 runs  +5 365  21 980 ✅ +5 365  0 💤 ±0  0 ❌ ±0 

Results for commit dcb5443. ± Comparison against base commit 7f28496.

This pull request removes 116 and adds 1692 tests. Note that renamed tests count towards both.


    internal static void Tick(IClock clock) { }
    public static IOther CreateClock(int seed) => new SystemClock();, The factory 'Production·Shop·CreateClock')
    public static Task Heat(IKettle kettle) => Task·CompletedTask;, Lib·IKettle)
    public static void Tick(IOther other) { }, The lifecycle hook 'Production·Shop·Tick')
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt111ConflictingProduction+BesideTheHandleOfAModuleOfAnotherAssembly ‑ AHookOfARegistrationThatProducesTheImplementationOtherwise_IsNotReportedAsUnapplied(
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt155CrossModuleDuplicate ‑ DoesNotReportWhenAContainerRegistersAnImplementationAModuleOfAnotherAssemblyBuildsThroughItsFactory([Container]
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt161EagerAsyncSingleton+InAModule ‑ IsAWarningInTheModulesOwnBuild(Singleton<IKettle>(Factory = nameof(Make), Eager = true, OnActivated = nameof(Heat)), public static IKettle Make() => new ColdKettle();
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt216PrivateModuleService ‑ External_DropsASingletonNothingStarts([Singleton<DataModule·Warmer, DataModule·IWarmer>]
…
Awaiten.Docs.Tests.DiagnosticsPageTests ‑ Page_ShouldDocumentEachDiagnostic(AWT260)
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt111ConflictingProduction+BesideTheHandleOfAModuleOfAnotherAssembly ‑ AHookOfARegistrationThatProducesTheImplementationOtherwise_IsNotReportedAsUnapplied(
[Singleton<Clock>(Factory = nameof(CreateB))], friend)
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt111ConflictingProduction+BesideTheHandleOfAModuleOfAnotherAssembly ‑ AHookOfARegistrationThatProducesTheImplementationOtherwise_IsNotReportedAsUnapplied(
[Singleton<Clock>(Factory = nameof(CreateB))], full)
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt111ConflictingProduction+BesideTheHandleOfAModuleOfAnotherAssembly ‑ AHookOfARegistrationThatProducesTheImplementationOtherwise_IsNotReportedAsUnapplied(
[Singleton<Clock>(Factory = nameof(CreateB))], reference)
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt155CrossModuleDuplicate ‑ DoesNotReportWhenAContainerRegistersAnImplementationAModuleOfAnotherAssemblyBuildsThroughItsFactory([Container]
[Import(typeof(KettleModule))]
[Import(typeof(FooModule))]
[Singleton<Kettle, IFoo>]
[Singleton<Cafe>]
public static partial class MyContainer;)
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt155CrossModuleDuplicate ‑ DoesNotReportWhenAContainerRegistersAnImplementationAModuleOfAnotherAssemblyBuildsThroughItsFactory([Container]
[Import(typeof(KettleModule))]
[Import(typeof(FooModule))]
[Singleton<Kettle, IFoo>]
public static partial class BaseContainer;

[Container(Extends = typeof(BaseContainer))]
[Singleton<Cafe>]
public static partial class MyContainer;)
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt161EagerAsyncSingleton+InAModule ‑ IsAWarningInTheModulesOwnBuild(Singleton<IKettle>(Factory = nameof(Make), Eager = true, OnActivated = nameof(Heat)), public static IKettle Make() => new ColdKettle();
    public static Task Heat(IKettle kettle) => Task·CompletedTask;, Lib·IKettle)
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt216PrivateModuleService ‑ External_DropsASingletonNothingStarts([Singleton<DataModule·Warmer, DataModule·IWarmer>]
[Singleton<DataModule·Warmer, IHeater>])
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt216PrivateModuleService ‑ External_ReportsAStartedSingleton([AsyncInitializer<DataModule·Warmer>(nameof(DataModule·Warmer·WarmAsync))]
[Singleton<DataModule·Warmer, DataModule·IWarmer>])
Awaiten.SourceGenerators.Tests.DiagnosticTests+Awt216PrivateModuleService ‑ External_ReportsAStartedSingleton([Singleton<DataModule·Warmer, DataModule·IWarmer>(Eager = true)]
[Singleton<DataModule·Warmer, IHeater>])
…

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

🚀 Benchmark Results

Compared to the latest run of main @​ 7f28496a. The time table marks when Awaiten gets more than 15% faster or slower, which can also come from a faster or slower runner. A relative change marks when Awaiten gets more than 15% faster or slower relative to MS.DI, Autofac, DryIoc and Simple Injector: 🔴 / 🟢 against all of them, 🔸 / 🔹 against some.

Time (Awaiten, latest main run → PR)

Benchmark main PR Δ
Build (Size=256) 212.5 ns 74.4 ns 🟢 -65%
Build (Size=8) 29.0 ns 11.5 ns 🟢 -60%
Realistic 269.4 ns 163.2 ns 🟢 -39%
Resolve (Size=256) 7.4 ns 3.2 ns 🟢 -57%
Resolve (Size=8) 6.5 ns 3.0 ns 🟢 -54%

Relative performance (how many times as long the other container takes as Awaiten, main → PR)

Benchmark vs MS.DI vs Autofac vs DryIoc vs Simple Injector
Build (Size=256) 58.4× → 95.3× 🟢 -39% 2211.3× → 5450.0× 🟢 -59% 156.3× → 302.2× 🟢 -48% 1272.5× → 2388.2× 🟢 -47%
Build (Size=8) 49.3× → 68.4× 🟢 -28% 679.4× → 1505.4× 🟢 -55% 19.3× → 34.2× 🟢 -44% 329.2× → 527.0× 🟢 -38%
Resolve (Size=256) 0.98× → 1.21× 🔹 -20% 15.5× → 17.9× 1.17× → 1.44× 🔹 -19% 1.94× → 1.89×
Resolve (Size=8) 1.14× → 1.49× 🔹 -23% 18.1× → 19.5× 1.33× → 1.50× 1.66× → 2.02× 🔹 -18%
All benchmarks compared to main
Benchmark Time Memory vs MS.DI vs Autofac vs DryIoc vs Simple Injector
Build (Size=256) 212.5 ns → 74.4 ns (-65%) 4,432 B → 4,432 B 58.4× → 95.3× 🟢 -39% 2211.3× → 5450.0× 🟢 -59% 156.3× → 302.2× 🟢 -48% 1272.5× → 2388.2× 🟢 -47%
Build (Size=8) 29.0 ns → 11.5 ns (-60%) 216 B → 216 B 49.3× → 68.4× 🟢 -28% 679.4× → 1505.4× 🟢 -55% 19.3× → 34.2× 🟢 -44% 329.2× → 527.0× 🟢 -38%
Realistic 269.4 ns → 163.2 ns (-39%) 568 B → 568 B 2.67× → 2.39× 24.3× → 21.3× 1.54× → 1.52× 2.69× → 2.35×
Resolve (Size=256) 7.4 ns → 3.2 ns (-57%) 0 B → 0 B 0.98× → 1.21× 🔹 -20% 15.5× → 17.9× 1.17× → 1.44× 🔹 -19% 1.94× → 1.89×
Resolve (Size=8) 6.5 ns → 3.0 ns (-54%) 0 B → 0 B 1.14× → 1.49× 🔹 -23% 18.1× → 19.5× 1.33× → 1.50× 1.66× → 2.02× 🔹 -18%
Raw results of BuildBenchmarks
BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
AMD EPYC 9V45 4.52GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.404
  [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4

Job=InProcess  Toolchain=InProcessEmitToolchain  IterationCount=15  
LaunchCount=1  WarmupCount=10  

Build Size Mean Error StdDev Ratio Allocated Alloc Ratio
Awaiten 8 11.53 ns 0.393 ns 0.368 ns 1.00 216 B 1.00
MsDI 8 788.72 ns 14.513 ns 13.576 ns 68.47 5688 B 26.33
Autofac 8 17,357.60 ns 250.592 ns 234.404 ns 1,506.81 32478 B 150.36
DryIoc 8 394.49 ns 9.555 ns 8.938 ns 34.25 1528 B 7.07
SimpleInjector 8 6,076.50 ns 67.514 ns 52.711 ns 527.50 24760 B 114.63
Awaiten 256 74.40 ns 0.246 ns 0.218 ns 1.00 4432 B 1.00
MsDI 256 7,089.84 ns 96.620 ns 85.651 ns 95.30 61016 B 13.77
Autofac 256 405,478.36 ns 2,257.123 ns 2,111.314 ns 5,450.08 716977 B 161.77
DryIoc 256 22,483.69 ns 402.161 ns 356.505 ns 302.21 80510 B 18.17
SimpleInjector 256 177,677.75 ns 2,556.294 ns 2,391.159 ns 2,388.19 573122 B 129.31
Raw results of RealisticResolveBenchmarks
BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
AMD EPYC 9V45 4.51GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.404
  [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4

Job=InProcess  Toolchain=InProcessEmitToolchain  IterationCount=15  
LaunchCount=1  WarmupCount=10  

Realistic Mean Error StdDev Ratio Allocated Alloc Ratio
Awaiten 163.2 ns 1.57 ns 1.39 ns 1.00 568 B 1.00
MsDI 389.7 ns 2.44 ns 2.28 ns 2.39 1104 B 1.94
Autofac 3,471.3 ns 23.17 ns 21.67 ns 21.27 10784 B 18.99
DryIoc 248.8 ns 1.86 ns 1.74 ns 1.52 944 B 1.66
SimpleInjector 383.3 ns 5.21 ns 4.62 ns 2.35 1096 B 1.93
Raw results of ResolveBenchmarks
BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
AMD EPYC 9V45 4.51GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.404
  [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4

Job=InProcess  Toolchain=InProcessEmitToolchain  IterationCount=15  
LaunchCount=1  WarmupCount=10  

Resolve Size Mean Error StdDev Ratio Allocated Alloc Ratio
Awaiten 8 3.004 ns 0.0718 ns 0.0672 ns 1.00 - NA
MsDI 8 4.480 ns 0.2079 ns 0.1736 ns 1.49 - NA
Autofac 8 58.466 ns 0.7142 ns 0.6331 ns 19.47 656 B NA
DryIoc 8 4.517 ns 0.1731 ns 0.1619 ns 1.50 - NA
SimpleInjector 8 6.054 ns 0.1471 ns 0.1304 ns 2.02 - NA
Awaiten 256 3.167 ns 0.0442 ns 0.0370 ns 1.00 - NA
MsDI 256 3.845 ns 0.0112 ns 0.0100 ns 1.21 - NA
Autofac 256 56.568 ns 1.0660 ns 0.9450 ns 17.86 656 B NA
DryIoc 256 4.562 ns 0.2608 ns 0.2439 ns 1.44 - NA
SimpleInjector 256 5.972 ns 0.1460 ns 0.1295 ns 1.89 - NA

@vbreuss
vbreuss force-pushed the fix/same-named-types-and-test-helper branch 3 times, most recently from d212140 to 7dfe5fe Compare November 15, 2026 11:55
…f the referenced assembly

RunWithGeneratedCompilationReference, RunWithModuleAndBase with BaseBuild.CompilationReference and Analyzer.RunWithCompilationReference referenced the generated library as a compilation without checking that it compiles, so a broken library build could pass in that mode while the emitted-assembly helpers already throw on it. They now fail with the library's errors, as EmitToReference does.
…r referenced assembly declares its full name (AWT260)

A container that imported modules of two libraries which both declare a public Lib.Clock emitted global::Lib.Clock, which is ambiguous between the references, so the generated code failed with CS0433 (and CS0677 for the volatile field of an instance handle). Plain C# can name such a type only through an extern alias, which the generator cannot add, so the container now reports AWT260 instead, once per type, at the import or registration that brings it into the graph, naming the assemblies that declare it.

The check covers the services of every registration that joins the graph, every implementation the container builds, the parameters of constructors, factories, hooks, async initializers and decorator predicates, injected properties and [ImportService] types, including type arguments and element types. A type internal to the other assembly, a default the container replaces and a same-named type the graph never needs are not reported. A type the project declares itself wins over a referenced one, so only the referenced one is reported there.
…T260)

A registration Key, a [FromKey] or a container-side property entry whose key is an enum constant or a typeof spells that type in the generated keyed dispatch and host forwarding, so a key type that another referenced assembly also declares slipped past AWT260 and the build failed with CS0433.

Hooks and decorator predicates of a module of another assembly bind through its generated Internals class, which the message named instead of the module the user wrote.

The remaining AWT260 paths (decorators, composites, open generic closings, [Arg], hooks, async initializers, predicates and Extends) had no tests. Reporting no longer allocates a list per type, and CollectExternalServiceTypes takes the names explicitly so no caller drops them by accident.
…cannot name (AWT260)

The generated container also spells the type of an [AsyncInitializer<T>] and the imported or inherited modules (and base container) whose handles, factories, hooks, predicates or wrappers it calls, so a same-named type in another reference still failed with CS0433 instead of AWT260.

A module is named only when the container calls into it, which the graph does not record in one place, so the emitted source decides; it is emitted a second time only when a module's name is ambiguous.
A reference with an extern alias stays out of global::, so the container names the type of the other assembly, as a test now proves.
Searching the emitted source for the module's name also matched a generic type of the same name, such as Lib.Mod<int> beside the module Lib.Mod, and reported a module the container never calls. The graph now reports a module or base container where it decides to call a member of it (a production member or generated factory, a hook, a predicate, a wrapper, a handle alias or setter) or names a type nested in it, like any other type.

The reports now run inside the graph build, so a base of the same assembly that cannot name its module fails the extending container too, instead of leaving it to emit code that does not compile.
…260)

A namespace of the same full name as a type the container needs, or an accessible type named like one of the type's namespaces, makes 'global::' fail with CS0434 just like a second type makes it fail with CS0433, so the container left generated code that did not compile instead of reporting AWT260. A namespace counts whatever the accessibility of its types, as the compiler sees it either way.
…s nothing from

The generated code names everything through 'global::', so an alias only helps when no type the container needs and no module it imports lives in the aliased assembly; the page did not say that a module imported through the alias counts too.
The inline ternary that picked the needer for each parameter was hard to read; a local computed once before the loop says what it decides.
…ke (AWT260)

A module's generated factory leaves deferred properties to setter wrappers the container calls with the dependency, so a same-named type there still broke the generated code with CS0433 instead of reporting AWT260.
…me itself

Keeping the container in a project that references only one of the declaring assemblies cannot help when that project is one of them. The docs also note the CS0436 warning the generated code then shares with the user's own code, which fails builds with warnings as errors.
@vbreuss
vbreuss force-pushed the fix/same-named-types-and-test-helper branch from 7dfe5fe to dcb5443 Compare November 15, 2026 13:10
@vbreuss
vbreuss enabled auto-merge (squash) November 15, 2026 13:10
@sonarqubecloud

Copy link
Copy Markdown

@vbreuss
vbreuss disabled auto-merge November 15, 2026 13:38
@vbreuss
vbreuss merged commit 8080761 into main Nov 15, 2026
24 of 25 checks passed
@vbreuss
vbreuss deleted the fix/same-named-types-and-test-helper branch November 15, 2026 13:38
github-actions Bot added a commit that referenced this pull request Nov 15, 2026
…ner cannot name because another referenced assembly declares its full name (AWT260) (#455) by Valentin Breuß
github-actions Bot added a commit that referenced this pull request Nov 15, 2026
…ner cannot name because another referenced assembly declares its full name (AWT260) (#455) by Valentin Breuß
@github-actions

Copy link
Copy Markdown

This is addressed in release v0.16.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working state: released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant