- ApplicationInsight version: 2.17 (Latest)
- .NET 5
Describe the bug
Grpc.Net.Client raises events that HttpCoreDiagnosticSourceListener listens to. The problem is that TypedFetchProperty assumes that the type passed here will always be the same. Grpc.Net.Client has a copy of the types passed to the listener.
|
var typedPropertyFetcher = typeof(TypedFetchProperty<,>); |
|
var instantiatedTypedPropertyFetcher = typedPropertyFetcher.GetTypeInfo().MakeGenericType( |
|
propertyInfo.DeclaringType, propertyInfo.PropertyType); |
|
return (PropertyFetch)Activator.CreateInstance(instantiatedTypedPropertyFetcher, propertyInfo); |
If System.Net.Http raises the events with one type, and Grpc.Net.Client raises the events with a different type, then TypedFetchProperty throws an error.
AI (Internal): [Microsoft-ApplicationInsights-Extensibility-DependencyCollector] HttpCoreDiagnosticSourceListener OnNext failed to call event handler. Error details 'System.InvalidCastException: [A]ActivityStartData cannot be cast to [B]ActivityStartData. Type A originates from 'Grpc.Net.ClientFactory, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad' in the context 'Default' at location '/app/Grpc.Net.ClientFactory.dll'.
Type B originates from 'System.Net.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' in the context 'Default' at location '/usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.4/System.Net.Http.dll'.
at Microsoft.ApplicationInsights.Common.PropertyFetcher.PropertyFetch.TypedFetchProperty`2.Fetch(Object obj)
at Microsoft.ApplicationInsights.DependencyCollector.Implementation.HttpCoreDiagnosticSourceListener.OnNext(KeyValuePair`2 evnt)'
To Reproduce
With AI configured, make a web request with HttpClient, and make a gRPC request with Grpc.Net.Client.
Whichever library makes the second request will fail because TypedFetchProperty has been created against the other libraries copy of the event objects.
Describe the bug
Grpc.Net.Client raises events that HttpCoreDiagnosticSourceListener listens to. The problem is that
TypedFetchPropertyassumes that the type passed here will always be the same. Grpc.Net.Client has a copy of the types passed to the listener.ApplicationInsights-dotnet/WEB/Src/Common/PropertyFetcher.cs
Lines 46 to 49 in 81288f2
If
System.Net.Httpraises the events with one type, andGrpc.Net.Clientraises the events with a different type, thenTypedFetchPropertythrows an error.To Reproduce
With AI configured, make a web request with HttpClient, and make a gRPC request with Grpc.Net.Client.
Whichever library makes the second request will fail because
TypedFetchPropertyhas been created against the other libraries copy of the event objects.