Description
We're seeing a high volume of these errors reported in our telemetry:
AI (Internal): [Microsoft-ApplicationInsights-Extensibility-DependencyCollector] Callback 'OnBeginSql' failed for id = '11495928'. Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
at System.Diagnostics.Activity.TrySetTraceIdFromParent()
at System.Diagnostics.Activity.GenerateW3CId()
at System.Diagnostics.Activity.Start()
at Microsoft.ApplicationInsights.DependencyCollector.Implementation.ClientServerDependencyTracker.BeginTracking(TelemetryClient telemetryClient) in ClientServerDependencyTracker.cs:line 44
at Microsoft.ApplicationInsights.DependencyCollector.Implementation.ProfilerSqlProcessingBase.OnBegin(Object thisObj) in ProfilerSqlProcessingBase.cs:line 238
This seems related to dotnet/runtime#745
The DotNet team has responded:
The problem here is not really System.DiagnosticSource as that one does dual-target for net46, the problem is that it depends on System.Memory which doesn't dual target. This means that every application that targets .NET Framework (version <= 4.7.1) and wants to install only the ApplicationInsights package, will require all of the netstandard facades given that System.Memory targets .NET Standard 2.0. This could be mitigated if we service the System.Memory package in order to also have it dual-target, so that it won't require all of the facades at runtime.
The DotNet team is working on a fix but does not have an ETA.
At this time we don't have a workaround, but I've read that some people are having success with binding redirects.