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

Microsoft.Data.SqlClient.SqlConnection' threw an exception with SnapshotCollector 1.4.0 and 1.4.1 #16

Closed
didaskein opened this issue Sep 25, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@didaskein
Copy link

No issue with the version : 1.3.7.5 of Microsoft.ApplicationInsights.SnapshotCollector

Since the upgrade to 1.4.0 (and same error with 1.4.1)

When we call EF core call to the SQL DB we get this error message :

System.TypeInitializationException: 'The type initializer for 'Microsoft.Data.SqlClient.SqlConnection' threw an exception.'
ArgumentException: Delegates must be of the same type.

at System.MulticastDelegate.CombineImpl(Delegate follow)
at System.Runtime.Loader.AssemblyLoadContext.add__unloading(Action1 value) at System.Runtime.Loader.AssemblyLoadContext.add_Unloading(Action1 value)
at Microsoft.Data.SqlClient.SqlDiagnosticListener..ctor(String name)
at Microsoft.Data.SqlClient.SqlConnection..cctor()

image

Thank you ! :-)

@pharring
Copy link
Member

@didaskein thanks for the bug report. I don't see SnapshotCollector in the code or in the call-stack, so I can't see how it's involved.
Could you give me some more context? If you have a minimal repro case, that would be even better.

What runtime are you targeting? .NET Core 3.1 or .NET 5, or something else?
SnapshotCollector does have code to hook the AssemblyLoadContext.Unloading event. I'll take a closer look.

@pharring pharring added the bug Something isn't working label Sep 27, 2021
@pharring
Copy link
Member

I think I know what's going on. Since we moved to a single "netstandard2.0" target, we use reflection to hook the AssemblyLoadContext.Default.Unloading event since it's available only in .NET Core apps. However, we took a liberty on the argument type of the handler (using 'object' instead of 'AssemblyLoadContext' since the latter is unmentionable). That's what leads to this exception when some other component also hooks the Unloading event.

I'll work on a fix for 1.4.2

@didaskein
Copy link
Author

i confirm the target version is net5.0 in the csproj ;)

@pharring
Copy link
Member

@didaskein please upgrade to 1.4.2 and try again. Let me know if there are further problems.

@didaskein
Copy link
Author

I confirm, it's working ! thank you for the fix ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants