# ELK APM .NET System.NullReferenceException

**URL:** <https://discuss.elastic.co/t/elk-apm-net-system-nullreferenceexception/371079>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [November 26, 2024, 11:51am UTC](https://discuss.elastic.co/t/elk-apm-net-system-nullreferenceexception/371079 "2024-11-26T11:51:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anders\_Ekdahl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anders_ekdahl/32/139483_2.png) [@Anders\_Ekdahl](https://discuss.elastic.co/u/Anders_Ekdahl)\
**Post date:** [November 26, 2024, 11:51am UTC](https://discuss.elastic.co/t/elk-apm-net-system-nullreferenceexception/371079/1 "2024-11-26T11:51:36Z")

</div>

We're using the Elastic.Apm NuGet package and noticed that it threw a NullReferenceException in the ElasticActivityListener.

The stack trace is:

```auto
System.NullReferenceException: Object reference not set to an instance of an object.
   at Elastic.Apm.Model.Span.<End>g__QueueSpan|117_0(Span span)
 
   at Elastic.Apm.Model.Span.End()
 
   at Elastic.Apm.OpenTelemetry.ElasticActivityListener.UpdateSpan(Activity activity, Span span)
 
   at Elastic.Apm.OpenTelemetry.ElasticActivityListener.<get_ActivityStopped>b__21_0(Activity activity)
 
   at System.Diagnostics.SynchronizedList`1.EnumWithAction(Action`2 action, Object arg)
 
   at System.Diagnostics.Activity.Stop()

```

**APM Agent language and version** :  
.NET NuGet package, Elastic.Api. Version: 1.30.1  
.NET version: 8

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:

It doesn't happen all the time, we've been running the Elastic.Apm package for a long time in multiple internal applications and this is the first time I've seen this error so it seems very hard to reproduce.

---

<div class="post-metadata">

**Author:** ![stevejgordon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevejgordon/32/80912_2.png) [@stevejgordon](https://discuss.elastic.co/u/stevejgordon)\
**Post date:** [February 3, 2025, 1:40pm UTC](https://discuss.elastic.co/t/elk-apm-net-system-nullreferenceexception/371079/2 "2025-02-03T13:40:07Z")

</div>

Apologies for the delay. The only relatively recent change was to add some extra `Trace` logging. Looking at the code, that could be a potential cause. Do you have trace logging enabled?
