-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Collecting database events from a .NET 6 application causes it to crash #57709
Comments
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti Issue DetailsDescriptionApplications that generate database operation related events (either by using EF Core or with using normal SQL queries) will crash when database operation related events are being collected from them due to a System.Reflection.AmbiguousMatchException. Below are instructions on how to repro the issue:
dotnet-trace collect -p --providers Microsoft-Diagnostics-DiagnosticSource:00000003:5:FilterAndPayloadSpecs=\SqlClientDiagnosticListener/System.Data.SqlClient.WriteCommandBefore@Activity1Start:-Command;Command.CommandText;ConnectionId;Operation;Command.Connection.ServerVersion;Command.CommandTimeout;Command.CommandType;Command.Connection.ConnectionString;Command.Connection.Database;Command.Connection.DataSource;Command.Connection.PacketSize\r\nSqlClientDiagnosticListener/System.Data.SqlClient.WriteCommandAfter@Activity1Stop:\r\nMicrosoft.EntityFrameworkCore/Microsoft.EntityFrameworkCore.Database.Command.CommandExecuting@Activity2Start:-Command.CommandText;Command;ConnectionId;IsAsync;Command.Connection.ClientConnectionId;Command.Connection.ServerVersion;Command.CommandTimeout;Command.CommandType;Command.Connection.ConnectionString;Command.Connection.Database;Command.Connection.DataSource;Command.Connection.PacketSize\r\nMicrosoft.EntityFrameworkCore/Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted@Activity2Stop:,System.Threading.Tasks.TplEventSource The application will then crash with the following exception: System.Reflection.AmbiguousMatchException: 'Ambiguous match found.' Where the stack trace looks like this: at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) ConfigurationOperating system: 64 bit Windows This seems to be specific to .NET 6, though I'm not sure which version it started to appear in. If you make the application target .NET 5 instead of .NET 6 then collecting database events from it will work as expected (won't cause the application to crash). Regression?This is a regression, if you change the application to target .NET 5 and everything else remains the same (same application, same OS, same version of dotnet-trace) then you will be able to collect database related events without issue. This is the version of .NET 5 I tested this with: 5.0.9 Other informationThere is no known workaround currently other than downgrading the version of .NET your application uses. This issue also blocks the Visual Studio Performance Profiler's database tool from supporting .NET 6 in any scenario since it collects database events from applications.
|
@josalem This is a regression between .NET 5 and .NET 6, possibly related to changes in DiagnosticSourceEventSource. |
I took a look, it's failing due to the code added in #55613. The EF code is trying to fire an event with a SqliteCommand as an argument and it has a Changing from It's definitely possible to fix once we give it some thought. |
Would it make sense calling first |
I had starting thinking along the same lines. The performance of this code that generates event manifests is already pretty bad, I doubt one extra call would make things noticeably worse. This is probably a good solution to start with |
Reopening till this is merged into .net6-rc2 |
Closing via #58212 |
Description
Applications that generate database operation related events (either by using EF Core or with using normal SQL queries) will crash when database operation related events are being collected from them due to a System.Reflection.AmbiguousMatchException. Below are instructions on how to repro the issue:
Run a .NET 6 application that does database operations either through EF Core or regular SQL commands (I can provide an example if needed via email)
Profile the application using dotnet-trace with the following command (this command is specific to Windows, if running on Linux the quotation marks in the providers string need to be slightly different):
dotnet-trace collect -p <PID> --providers Microsoft-Diagnostics-DiagnosticSource:00000003:5:FilterAndPayloadSpecs=\"SqlClientDiagnosticListener/System.Data.SqlClient.WriteCommandBefore@Activity1Start:-Command;Command.CommandText;ConnectionId;Operation;Command.Connection.ServerVersion;Command.CommandTimeout;Command.CommandType;Command.Connection.ConnectionString;Command.Connection.Database;Command.Connection.DataSource;Command.Connection.PacketSize\r\nSqlClientDiagnosticListener/System.Data.SqlClient.WriteCommandAfter@Activity1Stop:\r\nMicrosoft.EntityFrameworkCore/Microsoft.EntityFrameworkCore.Database.Command.CommandExecuting@Activity2Start:-Command.CommandText;Command;ConnectionId;IsAsync;Command.Connection.ClientConnectionId;Command.Connection.ServerVersion;Command.CommandTimeout;Command.CommandType;Command.Connection.ConnectionString;Command.Connection.Database;Command.Connection.DataSource;Command.Connection.PacketSize\r\nMicrosoft.EntityFrameworkCore/Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted@Activity2Stop:\",System.Threading.Tasks.TplEventSource
The application will then crash with the following exception:
System.Reflection.AmbiguousMatchException: 'Ambiguous match found.'
Where the stack trace looks like this:
Configuration
Operating system: 64 bit Windows
.NET version: 6.0.100-preview.7.21379.14
dotnet-trace version: 5.0.236902+5366510b270d0f0ebffc9e36e9496688b20b96c2
This seems to be specific to .NET 6, though I'm not sure which version it started to appear in. If you make the application target .NET 5 instead of .NET 6 then collecting database events from it will work as expected (won't cause the application to crash).
Regression?
This is a regression, if you change the application to target .NET 5 and everything else remains the same (same application, same OS, same version of dotnet-trace) then you will be able to collect database related events without issue. This is the version of .NET 5 I tested this with: 5.0.9
Other information
There is no known workaround currently other than downgrading the version of .NET your application uses. This issue also blocks the Visual Studio Performance Profiler's database tool from supporting .NET 6 in any scenario since it collects database events from applications.
The text was updated successfully, but these errors were encountered: