# UnityConsolTarget throws System.ObjectDisposedException

**URL:** <https://community.coherence.io/t/unityconsoltarget-throws-system-objectdisposedexception/800>\
**Category:** Bug reports\
**Created:** [March 25, 2026, 10:50am UTC](https://community.coherence.io/t/unityconsoltarget-throws-system-objectdisposedexception/800 "2026-03-25T10:50:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![owda](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@owda](https://community.coherence.io/u/owda)\
**Post date:** [March 25, 2026, 10:50am UTC](https://community.coherence.io/t/unityconsoltarget-throws-system-objectdisposedexception/800/1 "2026-03-25T10:50:43Z")

</div>

(Please make the title of your topic brief but informative, and post error messages under the next heading _Details and error message(s)_)

## Description, details and error message(s)

This issue occurs sporadically if the Visual Studio debugger is attached when entering play mode in Unity. The error that is thrown prevents Unity from running until F5 is hit on in Visual Studio, often more than once to progress. The error occurs in the Log method when trying to access StringBuilderCache.Value.

## Expected behaviour

_This section of code should prevent a blocking error from being thrown._

## Screenshots

_If applicable, add screenshots to help explain the problem._

## How to reproduce

**Rate: (Choose one, or describe it yourself)**  
_Sometimes_

**Steps:**

1. Attach the debugger
2. Enter play mode (happens maybe once or twice per day)

## Environment

SDK: 2.0.0  
Unity: 6.3.2f1  
OS/Platform: Windows 10

---

<div class="post-metadata">

**Author:** ![owda](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@owda](https://community.coherence.io/u/owda)\
**Post date:** [March 25, 2026, 12:32pm UTC](https://community.coherence.io/t/unityconsoltarget-throws-system-objectdisposedexception/800/2 "2026-03-25T12:32:30Z")

</div>

Update: it’s happening during a domain reload, so it’s probably that rather than entering play mode that causes the issue.

---

<div class="post-metadata">

**Author:** ![Filip](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/filip/32/142_2.png) [@Filip](https://community.coherence.io/u/Filip)\
**Post date:** [March 27, 2026, 1:38pm UTC](https://community.coherence.io/t/unityconsoltarget-throws-system-objectdisposedexception/800/3 "2026-03-27T13:38:28Z")

</div>

Hey!

Thanks for the report. Found the issue, the fix should be there in the next patch!

---

<div class="post-metadata">

**Author:** ![owda](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@owda](https://community.coherence.io/u/owda)\
**Post date:** [March 31, 2026, 8:26am UTC](https://community.coherence.io/t/unityconsoltarget-throws-system-objectdisposedexception/800/4 "2026-03-31T08:26:52Z")

</div>

Amazing, thanks for the speedy work

---

<div class="post-metadata">

**Author:** ![owda](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@owda](https://community.coherence.io/u/owda)\
**Post date:** [April 20, 2026, 4:23pm UTC](https://community.coherence.io/t/unityconsoltarget-throws-system-objectdisposedexception/800/5 "2026-04-20T16:23:20Z")

</div>

Hi, did this fix make it into 2.1.3?

---

<div class="post-metadata">

**Author:** ![Filip](https://dub1.discourse-cdn.com/flex017/user_avatar/community.coherence.io/filip/32/142_2.png) [@Filip](https://community.coherence.io/u/Filip)\
**Post date:** [April 21, 2026, 7:06am UTC](https://community.coherence.io/t/unityconsoltarget-throws-system-objectdisposedexception/800/6 "2026-04-21T07:06:06Z")

</div>

Apologies, but unfortunately not. All the patches on top of 2.1 were only critical fixes, everything else was pushed back to 2.2 for stability reasons.

The good news is, 2.2 is right around the corner as we’re entering the testing phase.

If you need the fix now, you can make the changes directly (requires package embedding if SDK is not coming from the asset store). The file is `Coherence.Log/LogTargets/UnityConsoleTarget.cs` - here’s the git patch:

```diff
diff --git a/Coherence.Log/LogTargets/UnityConsoleTarget.cs b/Coherence.Log/LogTargets/UnityConsoleTarget.cs
index be3a40a82..c0c30ebe1 100644
--- a/Coherence.Log/LogTargets/UnityConsoleTarget.cs
+++ b/Coherence.Log/LogTargets/UnityConsoleTarget.cs
@@ -68,11 +68,12 @@ namespace Coherence.Log.Targets
         /// </example>
         public bool AddSourceType { get; set; }
 
- private static readonly ThreadLocal<StringBuilder> StringBuilderCache = new(() => new StringBuilder());
+ [ThreadStatic]
+ private static StringBuilder stringBuilderCache;
 
         public void Log(LogLevel level, string message, (string key, object value)[] args, Logger logger)
         {
- var logBuilder = StringBuilderCache.Value;
+ var logBuilder = stringBuilderCache ??= new StringBuilder();
             logBuilder.Clear();
 
             if (AddTimestamp)

```
