ApplicationInsights-dotnet: EventSourceException whilte processing event "Exception" or "Metric"

Repro Steps

There were couple new issues reported in Application Insights SDK telemetry:

  • AI (Internal): EventSourceException while processing event "Exception": System.Reflection.TargetException:Non-static method requires a target.

  • AI (Internal): EventSourceException while processing event "Metric": System.Reflection.TargetException:Non-static method requires a target.

This issue seems to affect multiple customers.

Version Info

SDK Version : 2.5.1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 5
  • Comments: 30 (21 by maintainers)

Most upvoted comments

Just for convenience a stack dump as requested above:

Exception thrown: System.Reflection.TargetException: Non-static method requires a target.
 at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target) thrown at at reindlit.sparkleweb.app.Program.CurrentDomain_FirstChanceException(Object sender, FirstChanceExceptionEventArgs e) in D:\agent\_work\10\s\reindlit.sparkleweb.app\Program.cs:line 23
 at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
 at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
 at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
 at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
 at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
 at System.Diagnostics.Tracing.PropertyValue.<>c__DisplayClass33_0.<GetBoxedValueTypePropertyGetter>b__0(PropertyValue container)
 at System.Diagnostics.Tracing.NullableTypeInfo.WriteData(TraceLoggingDataCollector collector, PropertyValue value)
 at System.Diagnostics.Tracing.InvokeTypeInfo.WriteData(TraceLoggingDataCollector collector, PropertyValue value)
 at System.Diagnostics.Tracing.InvokeTypeInfo.WriteData(TraceLoggingDataCollector collector, PropertyValue value)
 at System.Diagnostics.Tracing.EventSource.WriteImpl(String eventName, EventSourceOptions& options, Object data, Guid* pActivityId, Guid* pRelatedActivityId, TraceLoggingEventTypes eventTypes)
 at System.Diagnostics.Tracing.EventSource.Write[T](String eventName, EventSourceOptions options, T data)
 at Microsoft.ApplicationInsights.Extensibility.Implementation.RichPayloadEventSource.WriteEvent[T](String eventName, String instrumentationKey, IDictionary`2 tags, T data, Int64 flags, EventKeywords keywords)
 at Microsoft.ApplicationInsights.Extensibility.Implementation.RichPayloadEventSource.Process(ITelemetry item)
 at Microsoft.ApplicationInsights.TelemetryClient.Track(ITelemetry telemetry)
 at Microsoft.ApplicationInsights.TelemetryClient.TrackTrace(TraceTelemetry telemetry)
 at Microsoft.ApplicationInsights.TelemetryClient.TrackTrace(String message)
 at reindlit.sparkleweb.app.Program.CurrentDomain_FirstChanceException(Object sender, FirstChanceExceptionEventArgs e) in D:\agent\_work\10\s\reindlit.sparkleweb.app\Program.cs:line 25

In addition there was an interesting link to this issue here.

It’s a bug in corefx and affects .NET Core only. We won’t try and work-around it in App Insights. We’ll get it fixed in .NET Core. If it’s a straightforward (low risk) fix, we’ll also push for porting the fix down-level into the LTS branch. Thanks for your help getting the call-stack and narrowing down the issue, @steven-r. This issue can probably be closed now that we understand what causes it and that we’ve decided not to do anything in App Insights.

Is there any suggested work-around for this in the meantime? This happened in our Azure App Service which caused our “Always On” app to stop and not restart, so our background tasks (ASP.NET Core Hosted Service) stopped running.

My thought is to just create an Azure Function App to hit the App Service URL every 10 seconds to ensure its running/restarted. Is that the best option here? It would be nice if “Always On” would restart an app on error but that’s a different topic for a different team.