-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Configuration binding source generator doesn't handle generics correctly #89273
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsWhen trying to use the configuration binder source generator with an expression that uses a closed-generic type, I'm getting a warning saying it isn't supported. However, since the expression is a closed-generic type, the type is able to be understood. In this case, the type is We have this case in ASP.NET Auth. Specifically the Blazor WASM project templates use this exact pattern. Repro steps
using Microsoft.Extensions.Configuration;
var config = new ConfigurationBuilder().Build();
AddOidcAuthentication(options =>
{
config.Bind("Local", options.ProviderOptions); // warning HERE
});
static void AddOidcAuthentication(Action<RemoteAuthenticationOptions<OidcProviderOptions>> configure)
{
configure(new());
}
public class RemoteAuthenticationOptions<TRemoteAuthenticationProviderOptions> where TRemoteAuthenticationProviderOptions : new()
{
public TRemoteAuthenticationProviderOptions ProviderOptions { get; } = new TRemoteAuthenticationProviderOptions();
}
public class OidcProviderOptions
{
public string? Authority { get; set; }
} <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0-preview.7.23370.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0-preview.7.23370.3" />
</ItemGroup>
</Project> Expected resultsThe above app should build successfully with no warnings or errors. Actual results
|
Thanks, I'll take a look. I think I fixed something similar in e4e0810#diff-c941b7a8491ae8b0d73a97808f886062a388c3d59da08b281d56eb0c2afbc2c5R126. |
@eerhardt per our offline discussion, there's a workaround for the templates (go back to disabling the generator for now) and we don't need a fix for this in Preview 7. We'll make a fix in RC. |
When trying to use the configuration binder source generator with an expression that uses a closed-generic type, I'm getting a warning saying it isn't supported.
However, since the expression is a closed-generic type, the type is able to be understood. In this case, the type is
OidcProviderOptions
.We have this case in ASP.NET Auth. Specifically the Blazor WASM project templates use this exact pattern.
https://github.com/dotnet/aspnetcore/blob/24bbfb6d8398684091cc970bd342df185c8f9421/src/ProjectTemplates/Web.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Program.cs#L15C1-L21
Repro steps
dotnet build
the following app.Expected results
The above app should build successfully with no warnings or errors.
Actual results
The text was updated successfully, but these errors were encountered: