-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConfigurationBinder source generator encounters namespace conflicts in using statements #93498
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescriptionWhen the first part of a namespace of a bound type exists under the Microsoft namespace an error will occur using Microsoft.Extensions.Configuration;
var c = new ConfigurationBuilder().Build();
c.Get<Foo.Bar.BType>();
namespace Microsoft.Foo
{
internal class AType {}
}
namespace Foo.Bar
{
internal class BType {}
}
This is happening because the generator places using statements in a namespace Hit this when porting eShopOnContainers. Reproduction StepsBuild Expected behaviorBuilds without issue Actual behaviorCompilation error. Regression?No Known WorkaroundsAlias the reference that has the conflicting namespace, change namespace names, etc. ConfigurationNo response Other informationNo response
|
Working around dotnet/runtime#93498
I'm hitting this same issue trying to use the ConfigBinder Source Generator with the Azure SDK: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
<NoWarn>$(NoWarn);SYSLIB1100;SYSLIB1101</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0-rtm.23511.16" />
<PackageReference Include="Azure.Data.Tables" Version="12.8.1" />
</ItemGroup>
</Project> using Azure.Data.Tables;
using Microsoft.Extensions.Configuration;
Console.WriteLine("Hello, World!");
static void BindToConfiguration(TableClientOptions options, IConfiguration configuration)
{
var configurationOptionsSection = configuration.GetSection("ConfigurationOptions");
configurationOptionsSection.Bind(options);
} results in:
The issue here is that all the Azure SDK libraries put some extensions class in the namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration
{
using Azure.Core;
using Azure.Data.Tables; Since it is in |
We need to use a global prefix when importing namespaces here. |
We should actually never add using statements here. Those using statements are being driven by types referenced across many files, combining all the using statements in a single file can cause name conflicts (even ignoring this special case). I heard from @captainsafia via @eerhardt
We need to do this. Any reference to a type without a |
Yep, here is the configuration we use for displaying type names in RDG. |
Description
When the first part of a namespace of a bound type exists under the Microsoft namespace an error will occur
This is happening because the generator places using statements in a namespace
Microsoft.Extensions.Configuration.Binder.SourceGeneration
and this will cause the compiler to first search in containing namespaces at every level before considering the global namespace for usings placed in that namespace.Hit this when porting eShopOnContainers.
Reproduction Steps
Build
namespaceConflict.zip
Expected behavior
Builds without issue
Actual behavior
Compilation error.
Regression?
No
Known Workarounds
Alias the reference that has the conflicting namespace, change namespace names, etc.
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: