Description
When trying to use the ConfigurationBinder source generator with the Azure SDK's ClientOptions objects I'm getting compile errors. However, the compile errors come from a method that isn't even invoked.
Reproduction Steps
<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.Storage.Blobs" Version="12.17.0" Aliases="AzureStorageBlobs" />
</ItemGroup>
</Project>
extern alias AzureStorageBlobs;
global using AzureStorageBlobs.Azure.Storage.Blobs;
global using AzureStorageBlobs.Azure.Storage.Blobs.Models;
using Microsoft.Extensions.Configuration;
Console.WriteLine("Hello, World!");
static void BindToConfiguration(BlobClientOptions options, IConfiguration configuration)
{
var configurationOptionsSection = configuration.GetSection("ConfigurationOptions");
configurationOptionsSection.Bind(options);
}
namespace Azure.Storage.Blobs.Models { }
(note the alias, global usings, and empty namespace is to work around #93498 and #94065
Expected behavior
The source generator should work for these options types. The Azure SDK currently uses the reflection-based config binder here:
https://github.com/Azure/azure-sdk-for-net/blob/6d43c499a7cd6bf6b1aba9ea220ba22e54e6f7e1/sdk/extensions/Microsoft.Extensions.Azure/src/AzureClientBuilderExtensions.cs#L83
Actual behavior
You get a build error:
C:\Users\eerhardt\source\repos\ConsoleApp101\ConsoleApp101\Microsoft.Extensions.Configuration.Binder.SourceGeneration\Microsoft.Extensions.Configuration.Binder.SourceGeneration.ConfigurationBindingGenerator\BindingExtensions.g.cs(450,56,450,58): error CS0266: Cannot implicitly convert type 'int' to 'Azure.Storage.Blobs.BlobClientOptions.ServiceVersion'. An explicit conversion exists (are you missing a cast?)
This is coming from this generated code:
public static BlobClientOptions InitializeBlobClientOptions(IConfiguration configuration, BinderOptions? binderOptions)
{
BlobClientOptions.ServiceVersion version = 17;
if (configuration["Version"] is string value73)
{
version = ParseEnum<BlobClientOptions.ServiceVersion>(value73, () => configuration.GetSection("Version").Path);
}
return new BlobClientOptions(version);
}
However, this InitializeBlobClientOptions method isn't even called.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Description
When trying to use the ConfigurationBinder source generator with the Azure SDK's ClientOptions objects I'm getting compile errors. However, the compile errors come from a method that isn't even invoked.
Reproduction Steps
(note the alias, global usings, and empty namespace is to work around #93498 and #94065
Expected behavior
The source generator should work for these options types. The Azure SDK currently uses the reflection-based config binder here:
https://github.com/Azure/azure-sdk-for-net/blob/6d43c499a7cd6bf6b1aba9ea220ba22e54e6f7e1/sdk/extensions/Microsoft.Extensions.Azure/src/AzureClientBuilderExtensions.cs#L83
Actual behavior
You get a build error:
This is coming from this generated code:
However, this
InitializeBlobClientOptionsmethod isn't even called.Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response