Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' #3272

Closed
3keyroman opened this issue Feb 14, 2024 · 5 comments
Assignees
Milestone

Comments

@3keyroman
Copy link

Running the ASP NET 6 application in container and autoinstrumenting using ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-dotnet:1.2.0, managed by OpenTelemetry Operator version 0.93.0 resulting in:

[2024-02-14T13:36:13.9101586Z] [Information] Managed Loader TryLoadManagedAssembly()
[2024-02-14T13:36:14.0621165Z] [Error] Error when loading managed assemblies. Exception has been thrown by the target of an invocation.
Exception: Exception has been thrown by the target of an invocation.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.IO.FileLoadException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)
File name: 'System.Diagnostics.DiagnosticSource, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
 ---> System.IO.FileLoadException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.InternalLoadFromPath(String assemblyPath, String nativeImagePath)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
   at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
   at System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at OpenTelemetry.AutoInstrumentation.Loader.Loader.TryLoadManagedAssembly() in /_/src/OpenTelemetry.AutoInstrumentation.Loader/Loader.cs:line 72

Trying different versions of ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-dotnet, every time with the similar result, that the System.Diagnostics.DiagnosticSource cannot be loaded.

I am able to make it work only by adding the following dependency to project:

<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />

Is it expected behaviour? Should be the System.Diagnostics.DiagnosticSource always added to project to make it work? I was not able to find information about that in documentation.

I think that the autoinstrumentation should be able to make it work without requiring any dependencies to be added to the application. In many cases, we do not have the application code and dependencies under control and we cannot add it there.

@muhaook
Copy link

muhaook commented Feb 15, 2024

I think the issue was a bit different between 1.2.0 and 1.3.0.
With 1.3.0, the exception was FileNotFoundException while with 1.2.0, it was FileLoadException

in 1.3.0, .NET auto-instrumentation stopped shipping System.Diagnostics.DiagnosticSource.dll in the release. that may be why it was FileNotFound
in 1.2.0, .NET auto-instrumentation did ship System.Diagnostics.DiagnosticSource.dll in the release, its version is 7.0.0.

exception in 1.3.0

Exception: Exception has been thrown by the target of an invocation.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

File name: 'System.Diagnostics.DiagnosticSource, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at OpenTelemetry.AutoInstrumentation.Loader.Loader.TryLoadManagedAssembly() in /_/src/OpenTelemetry.AutoInstrumentation.Loader/Loader.cs:line 59

@rajkumar-rangaraj
Copy link
Contributor

@3keyroman Are these self-contained apps? A self-contained app has limitations, and your current workaround seems to be the best solution. Alternatively, you could use the OpenTelemetry.AutoInstrumentation NuGet package. Details can be found in our troubleshooting document.

If it's not a self-contained app and you have set additional dependencies and runtime store environment variables, it should automatically upgrade System.Diagnostics.DiagnosticSource.

Also, were there direct package references or transient package references to System.Diagnostics.DiagnosticSource in the app? Could you please share the deps.json file from the application to help troubleshoot the issue?"

@lubomirw
Copy link

@rajkumar-rangaraj Hi there, I was working on resolving this issue with @3keyroman. Application is not self-contained and running in Docker on standard image mcr.microsoft.com/dotnet/aspnet:6.0. Other thing maybe worth mentioning is that in Dockerfile we are setting following variable

ENV COMPlus_EnableDiagnostics=0

Originally, before workaround, System.Diagnostics.DiagnosticSource was there as transient package reference in version 6.0.1

I am attaching deps.json for reference.

@pjanotti pjanotti added this to the 1.5.0 milestone Feb 21, 2024
@rajkumar-rangaraj
Copy link
Contributor

System.Diagnostics.DiagnosticSource was there as transient package reference in version 6.0.1

The OpenTelemetry .NET SDK has a reference to the 8.0.0 System.Diagnostics.DiagnosticSource. If an app’s local reference of System.Diagnostics.DiagnosticSource is lower than 8.0.0, it will end up with a FileLoadException. This is expected behavior. The solution documented in this troubleshooting article should help resolve the issue. - https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/docs/troubleshooting.md#assembly-version-conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants