Skip to content

Microsoft.Extensions.Azure 1.7.1: Code doesn't compile due to potentially outdated documentation #39935

Open
@sgabler

Description

@sgabler

The documentation seems outdated. I pasted the code from the docs, but it doesn't compile for me.

image

Here is my Program.cs

using Azure.Core;
using Azure.Identity;
using Microsoft.Extensions.Azure;

var host = Host.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration((hostingContext, config) =>
    {
        config.Sources.Clear();

        config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
        config.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true);
        config.AddJsonFile("appsettings.k8s.json", optional: true, reloadOnChange: false);
    })
    .ConfigureServices((hostContext, services) =>
    {
        // Registering policy to use in ConfigureDefaults later
        services.AddSingleton<DependencyInjectionEnabledPolicy>();

        services.AddAzureClients(builder => {
            // Register blob service client and initialize it using the KeyVault section of configuration
            builder.AddSecretClient(Configuration.GetSection("KeyVault"))
                // Set the name for this client registration
                .WithName("NamedBlobClient")
                // Set the credential for this client registration
                .WithCredential(new ClientSecretCredential("<tenant_id>", "<client_id>", "<client_secret>"))
                // Configure the client options
                .ConfigureOptions(options => options.Retry.MaxRetries = 10);

            // Adds a secret client using the provided endpoint and default credential set later
            builder.AddSecretClient(new Uri("http://my.keyvault.com"));

            // Configures environment credential to be used by default for all clients that require TokenCredential
            // and doesn't override it on per registration level
            builder.UseCredential(new EnvironmentCredential());

            // This would use configuration for auth and client settings
            builder.ConfigureDefaults(hostContext.Configuration.GetSection("Default"));

            // Configure global retry mode
            builder.ConfigureDefaults(options => options.Retry.Mode = RetryMode.Exponential);

            // Advanced configure global defaults
            builder.ConfigureDefaults((options, provider) => options.AddPolicy(provider.GetService<DependencyInjectionEnabledPolicy>(), HttpPipelinePosition.PerCall));

            // Register blob service client and initialize it using the Storage section of configuration
            builder.AddBlobServiceClient(Configuration.GetSection("Storage"))
                .WithVersion(BlobClientOptions.ServiceVersion.V2019_02_02);
        });
    })
    .Build();

await host.RunAsync();

My csproj file:

<Project Sdk="Microsoft.NET.Sdk.Worker">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <!-- Code Analysis (https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview) - BEGIN -->
    <EnableNETAnalyzers>true</EnableNETAnalyzers>
    <AnalysisMode>Default</AnalysisMode>
    <AnalysisLevel>latest</AnalysisLevel>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <!-- Code Analysis - END -->
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="IDisposableAnalyzers" Version="4.0.7">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.1" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
  </ItemGroup>

  <ItemGroup>
    <Content Include="..\.dockerignore">
      <Link>.dockerignore</Link>
    </Content>
    <Content Update="appsettings.Development.json">
      <DependentUpon>appsettings.json</DependentUpon>
    </Content>
  </ItemGroup>

</Project>

Could you please take a look at what might be wrong here?


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClientThis issue points to a problem in the data-plane of the library.ExtensionsASP.NET Core extensionsbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions