Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.26k stars 4.6k forks source link

[BUG] BCL AsyncInterfaces runtime error on upgrade - Azure.Monitor.OpenTelemetry.AspNetCore 1.1.0 #41747

Closed BC89 closed 6 months ago

BC89 commented 7 months ago

Library name and version

Azure.Monitor.OpenTelemetry.AspNetCore 1.1.0

Describe the bug

Running .Net 8 version 1.0.0 of Azure.Monitor.OpenTelemetry.AspNetCore and pulling down the latest version, 1.1.0 throws an error at runtime, Minimal WebAPI.

Docker - Linux

  <ItemGroup>
    <PackageReference Include="AsyncFixer" Version="1.6.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
    <PackageReference Include="Azure.Identity" Version="1.10.4" />
    <PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.20.0-beta.1" />
    <PackageReference Include="Azure.Storage.Files.Shares" Version="12.18.0-beta.1" />
    <PackageReference Include="Bogus" Version="35.4.0" />
    <PackageReference Include="Dapr.AspNetCore" Version="1.12.0" />
    <PackageReference Include="Dapr.Extensions.Configuration" Version="1.12.0" />
    <PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.5.0" />
    <PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="6.0.0-preview.4.21253.5" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Graph" Version="5.41.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="SimpleDateTimeProvider" Version="2024.2.1.79" />
    <PackageReference Include="Stripe.net" Version="43.11.0" />
    <PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.8" />
    <PackageReference Include="QuestPDF" Version="2023.12.4" />
    <PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0.1" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.7" />
  </ItemGroup>

Expected behavior

Upgrade to 1.1.0 without issue.

Actual behavior

Runtime error.

System.Reflection.ReflectionTypeLoadException HResult=0x80131602 Message=Unable to load one or more of the requested types. Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Source=System.Private.CoreLib

Reproduction Steps

Run api.

Environment

Microsoft Visual Studio Professional 2022 (64-bit) - Preview Version 17.9.0 Preview 5.0

Installed Version: Professional

Visual C++ 2022 00483-10050-37560-AA595 Microsoft Visual C++ 2022

ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 17.9.195.45391 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.9.195.45391 Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio 2.6.5000.0 Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 17.9.195.45391 Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0 Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 4.9.0-3.24073.3+d460b277f7dc6c563ace0d5558c3acfde9f2c1ff C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 17.0.24002.3 Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Entity Framework Core Power Tools 2.6 Adds useful design-time EF Core DbContext features to the Visual Studio Solution Explorer context menu.

Microsoft Azure Hive Query Language Service 2.6.5000.0 Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.6.5000.0 Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Node.js Tools 1.5.50908.1 Commit Hash:c294679b821c4b8f7f9c6db3827b7655db80fc28 Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager 6.9.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Office Developer Tools for Visual Studio 17.6.34328.02 Microsoft Office Developer Tools for Visual Studio

Python - Django support 17.0.24002.3 Provides templates and integration for the Django web framework.

Python - Profiling support 17.0.24002.3 Profiling support for Python projects.

Python with Pylance 17.0.24002.3 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Razor (ASP.NET Core) 17.9.2.2405304+df383360c34ada8889fdf18dc36d245f2938db66 Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.9.48.0 Microsoft SQL Server Data Tools

Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

TypeScript Tools 17.0.30103.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.9.0-3.24073.3+d460b277f7dc6c563ace0d5558c3acfde9f2c1ff Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Cross Platform Mobile Development (Android) 15.0.34511.75 Visual C++ for Cross Platform Mobile Development (Android)

Visual F# Tools 17.9.0-beta.23614.3+a521e1cd420beb56c15faf6836184fadd2b7937a Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

Workflow Manager Tools 1.0 1.0 This package contains the necessary Visual Studio integration components for Workflow Manager.

github-actions[bot] commented 7 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @cijothomas @rajkumar-rangaraj @reyang @TimothyMothra @vishweshbankwar.

github-actions[bot] commented 7 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @cijothomas @rajkumar-rangaraj @reyang @TimothyMothra @vishweshbankwar.

TimothyMothra commented 7 months ago

Hi @BC89, I'm not able to reproduce this. Can you please share a minimal repro?

This is what I tried: https://learn.microsoft.com/aspnet/core/tutorials/min-web-api

csproj

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.1.0" />
  </ItemGroup>
</Project>

Program.cs

namespace WebApplication4
{
    using Azure.Monitor.OpenTelemetry.AspNetCore;

    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);
            builder.Services.AddOpenTelemetry().UseAzureMonitor(x => x.ConnectionString = "...");
            var app = builder.Build();

            app.MapGet("/", () => "Hello World!");

            app.Run();
        }
    }
}
TimothyMothra commented 7 months ago

Hi @BC89, Can you please share what cmd you're using to publish your application? (dotnet publish) ? We're curious if you're trimming your application.

BC89 commented 7 months ago

With visual studio I'm simply F5ing to launch my docker compose which then spins up all the individual docker files. Do you see the list of other nugets I'm pulling in. Feels like there may be a conflict somewhere within the tree.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Timothy Mothra @.> Sent: Wednesday, February 7, 2024 4:11:23 PM To: Azure/azure-sdk-for-net @.> Cc: Brendan Carroll @.>; Mention @.> Subject: [External Email] Re: [Azure/azure-sdk-for-net] [BUG] BCL AsyncInterfaces runtime error on upgrade - Azure.Monitor.OpenTelemetry.AspNetCore 1.1.0 (Issue #41747)

From @. 410-316-7820 This is an External Email from outside of KCI.


Hi @BC89https://github.com/BC89, Can you please share what cmd you're using to publish your application? (dotnet publish) ? We're curious if you're trimming your application.

— Reply to this email directly, view it on GitHubhttps://github.com/Azure/azure-sdk-for-net/issues/41747#issuecomment-1932916723, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAZFIM6VVG4VZIJAECTUZ7DYSPUXXAVCNFSM6AAAAABCWXKSEKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZSHEYTMNZSGM. You are receiving this because you were mentioned.Message ID: @.***>

TimothyMothra commented 7 months ago

Sorry, I don't see the list of nugets. If you can share a minimal repro that would help investigate. If that's too large to share, you can create a new github repo to host a sample app.

Edit: I found the list of packages in your original post. Github hid the XML tags. I changed the formatting to make it display. There are several packages here that I'm not familiar with, I'll need more time to investigate. Again, if you can share a minimal repro, that would speed up the investigation.

BC89 commented 7 months ago

My suspicion is this is related to a conflict with AutoMapper's depedencies but here is the nugs:


  <ItemGroup>
    <PackageReference Include="AsyncFixer" Version="1.6.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="AutoMapper" Version="13.0.1" />
    <PackageReference Include="Azure.Identity" Version="1.10.4" />
    <PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.6.0" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.20.0-beta.1" />
    <PackageReference Include="Azure.Storage.Files.Shares" Version="12.18.0-beta.1" />
    <PackageReference Include="Bogus" Version="35.4.0" />
    <PackageReference Include="Dapr.AspNetCore" Version="1.12.0" />
    <PackageReference Include="Dapr.Extensions.Configuration" Version="1.12.0" />
    <PackageReference Include="Magick.NET-Q16-AnyCPU" Version="13.6.0" />
    <PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="6.0.0-preview.4.21253.5" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Graph" Version="5.42.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="SimpleDateTimeProvider" Version="2024.2.1.79" />
    <PackageReference Include="Stripe.net" Version="43.11.0" />
    <PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.8" />
    <PackageReference Include="QuestPDF" Version="2023.12.5" />
    <PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0.1" />
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.7" />
  </ItemGroup>
TimothyMothra commented 6 months ago

We released a new beta version of Azure.Monitor.OpenTelemetry.AspNetCore which we believe will address this issue. https://www.nuget.org/packages/Azure.Monitor.OpenTelemetry.AspNetCore/1.2.0-beta.2

I'm going to close this Issue. If you have any more problems, please respond.

BC89 commented 6 months ago

I've downloaded the beta and am now seeing the following in my local DEV environment at runtime:

Azure.Identity: Information: VisualStudioCredential.GetToken was unable to retrieve an access token. Scopes: [ https://monitor.azure.com//.default ] ParentRequestId: 11f09a97-dcda-42bb-87e8-2d23ab1167c7 Exception: Azure.Identity.CredentialUnavailableException (0x80131500): Process "/usr/share/dotnet/dotnet" has non-json output: Error: WAM Error  \n Error Code: 3399942151 \n Error Message: NoNetwork \n WAM Error Message: The download has failed (the connection was interrupted). \n Internal Error Code: 557973641 \n Possible cause: no Internet connection .
 ---> System.Text.Json.JsonReaderException (0x80131500): 'E' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
      VisualStudioCredential.GetToken was unable to retrieve an access token. Scopes: [ https://monitor.azure.com//.default ] ParentRequestId: 11f09a97-dcda-42bb-87e8-2d23ab1167c7 Exception: Azure.Identity.CredentialUnavailableException (0x80131500): Process "/usr/share/dotnet/dotnet" has non-json output: Error: WAM Error  \n Error Code: 3399942151 \n Error Message: NoNetwork \n WAM Error Message: The download has failed (the connection was interrupted). \n Internal Error Code: 557973641 \n Possible cause: no Internet connection .
       ---> System.Text.Json.JsonReaderException (0x80131500): 'E' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
Azure.Identity: Information: DefaultAzureCredential.GetToken was unable to retrieve an access token. Scopes: [ https://monitor.azure.com//.default ] ParentRequestId: 11f09a97-dcda-42bb-87e8-2d23ab1167c7 Exception: Azure.Identity.CredentialUnavailableException (0x80131500): Process "/usr/share/dotnet/dotnet" has non-json output: Error: WAM Error  \n Error Code: 3399942151 \n Error Message: NoNetwork \n WAM Error Message: The download has failed (the connection was interrupted). \n Internal Error Code: 557973641 \n Possible cause: no Internet connection .
 ---> System.Text.Json.JsonReaderException (0x80131500): 'E' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
info: Azure.Identity[3]
      DefaultAzureCredential.GetToken was unable to retrieve an access token. Scopes: [ https://monitor.azure.com//.default ] ParentRequestId: 11f09a97-dcda-42bb-87e8-2d23ab1167c7 Exception: Azure.Identity.CredentialUnavailableException (0x80131500): Process "/usr/share/dotnet/dotnet" has non-json output: Error: WAM Error  \n Error Code: 3399942151 \n Error Message: NoNetwork \n WAM Error Message: The download has failed (the connection was interrupted). \n Internal Error Code: 557973641 \n Possible cause: no Internet connection .
       ---> System.Text.Json.JsonReaderException (0x80131500): 'E' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.

MS seems to be having a hell of a time getting Azure Identity straight for local development in a Linx Docker container. The fall-through options on DefaultAzureCredentials keep shifting with every release of the SDK and compatibility issues arise when newer versions of VS 2022 are released. It's very frustrating.

Locally it now looks like this works:

 var credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions
        {
            TenantId = tenantid,
            ManagedIdentityClientId = managedidentityclientid,
#if DEBUG
            // This is a temporary workaround to allow local development without managed identity.  Remove this block when the issue is resolved.
            ExcludeManagedIdentityCredential = true
#endif
        });
TimothyMothra commented 6 months ago

Hi @BC89, that's a separate issue. You should open a new issue to get support with Azure.Identity.