csharp-netcore
csharp-netcore copied to clipboard
NullReferenceException during reflection of diagnostic events
Hello, we're using opentracing library for ASP.NET Core project and we're experiencing the NullReferenceException
all the time.
WARN 2023-01-11 08:16:17,048 class:OpenTracing.Contrib.NetCore.AspNetCore.AspNetCoreDiagnostics topic:null ip:null reqid:5e01741e-f6b3-47a4-af32-5a41e5879cb3 partner:null action:null uid:null msg:Event-Exception: Microsoft.AspNetCore.Mvc.BeforeActionResult System.NullReferenceException: Object reference not set to an instance of an object. at System.Object.GetType() at OpenTracing.Contrib.NetCore.AspNetCore.MvcEventProcessor.ProcessEvent(String eventName, Object arg) at OpenTracing.Contrib.NetCore.AspNetCore.AspNetCoreDiagnostics.OnNext(String eventName, Object untypedArg) at OpenTracing.Contrib.NetCore.Internal.DiagnosticListenerObserver.System.IObserver<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.OnNext(KeyValuePair`2 value)
I've investigated library code and found that during event BeforeActionResult for ASP.NET Core, we're trying to grab property Result
using typeInfo.GetDeclaredProperty()
of type BeforeActionResultEventData
(https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.diagnostics.beforeactionresulteventdata?view=aspnetcore-7.0).
The only problem is that this property name is passed to PropertyFetcher
in lowercase (aka "result" instead of "Result") which always results in null
, because GetDeclaredProperty
method is case-sensitive.
Code line with the issue: https://github.com/opentracing-contrib/csharp-netcore/blob/master/src/OpenTracing.Contrib.NetCore/AspNetCore/AspNetCoreDiagnostics.cs#L224C54-L224C54
Could you please advice - is it smth that is expected or I'm doing smth wrong?
Thanks!