-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Description
When 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 {}
}C:\scratch\namespaceConflict\Microsoft.Extensions.Configuration.Binder.SourceGeneration\Microsoft.Extensions.Configuration.Binder.SourceGeneration.ConfigurationBindingGenerator\BindingExtensions.g.cs(22,15): error CS0234: The type or namespace name 'Bar' does not exist in the namespace 'Microsoft.Foo' (are you missing an assembly reference?) [C:\scratch\namespaceConflict\namespaceConflict.csproj]
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