Closed
Description
From @andrewlock in #44493 (comment):
One potential issue I can foresee with the design of the generated code (because I've run into a similar issue with my own generators) is around internal
classes and InternalsVisibleTo
.
The fact that the generated code is always a fixed type (GeneratedConfigurationBinder
) in the global namespace, means that something like this will no longer compile:
Project 1:
[assembly:InternalsVisible2(Project2)]
var config = new ConfigurationBuilder().Build();
var settings = new SomeOptions();
section.Bind(settings);
Project 2: (has a <ProjectReference>
to Project1)
var config = new ConfigurationBuilder().Build();
var settings = new MoreOptions();
section.Bind(settings); // 👈 error
Gives
[CS0121] The call is ambiguous between the following methods or properties: 'GeneratedConfigurationBinder.Configure<T>(Microsoft.Extensions.DependencyInjection.IServiceCollection, Microsoft.Extensions.Configuration.IConfiguration)' and 'GeneratedConfigurationBinder.Configure<T>(Microsoft.Extensions.DependencyInjection.IServiceCollection, Microsoft.Extensions.Configuration.IConfiguration)'
You might consider it an edge case, but it was one of the first issues I ran into when building my first source generator.
Note: I've just seen that preview 4 bits are going onto NuGet, so apologies if this is no longer relevant! :D (Edit: looks like the preview 3 package is broken for me)