ApplicationInsights-dotnet: Getting error: System.IO.FileNotFoundException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource when running app in linux container
Setup an ASP.NET Core application to use Microsoft.ApplicationInsights.AspNetCore. Runs fine locally (MacOS), but when published as a linux app and deployed to a linux instance, it throws the below error when attempting to call AddApplicationInsightsTelemetry.
2021-03-17T09:59:25.953-04:00 [APP/PROC/WEB/0] [ERR] Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
2021-03-17T09:59:25.953-04:00 [APP/PROC/WEB/0] [ERR] File name: 'System.Diagnostics.DiagnosticSource, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
2021-03-17T09:59:25.953-04:00 [APP/PROC/WEB/0] [ERR] at Microsoft.Extensions.DependencyInjection.ApplicationInsightsExtensions.AddApplicationInsightsTelemetry(IServiceCollection services)
Configuration: .NET core 3.1 Linux Dependencies Microsoft.AspNetCore.Owin 3.1.1 Microsoft.AspNetCore.Server.Kestrel 2.2.0 Microsoft.ApplicationInsights.AspNetCore 2.17.0 System.Diagnostics.DiagnosticSource 5.0.1
I set the application key by environment variable (APPINSIGHTS_INSTRUMENTATIONKEY). I have verified that I am are setting it properly. I have also ran a variation where I do set the key inside of the appsettings.json, but that also returns the same error.
I have also tried downgrading Microsoft.ApplicationInsights.AspNetCore to 2.16.0, but that did not help.
Is there a known issue and/or workaround for this configuration?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 18 (8 by maintainers)
Commits related to this issue
- Work around issue https://github.com/microsoft/ApplicationInsights-dotnet/issues/2187 — committed to Azure/Industrial-IoT by marcschier 3 years ago
We have a similar problem on Windows, anything above 2.15.0 brings in System.Diagnostics.DiagnosticSource which is 5.0.x.
I really wish they hadn’t taken a dependency on something from the 5.x versioning because it currently breaks within any app running pre-.NET 5.0.
Our Azure Functions are still on .NET Core 3.1, and if I upgrade AppInsights past 2.15, I start to get missing method exceptions.
Personally, I think this isn’t right. On non-.NET 5.0, it shouldn’t be depending on anything from 5.x versioning.