You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Crash: "Object synchronization method was called from an unsynchronized block of code" in DotnetGlobalToolInstaller.EnsureCoreAsync (Mutex.ReleaseMutex) #145
System.ApplicationException: Object synchronization method was called from an unsynchronized block of code.
at System.Threading.Mutex.ReleaseMutex()
at Studio.Common.DotnetGlobalToolInstaller.EnsureCoreAsync(...)
The exception is thrown from Mutex.ReleaseMutex() (internal .NET implementation) when Win32Native.ReleaseMutex fails.
This happens during resumption of an async method (EnsureCoreAsync).
Environment
IDE: Microsoft Visual Studio Enterprise 2026 (18.10.0-insiders)
OS: Windows_NT
Process: devenv.exe (PID 22796)
Thread: 4852 (where the exception occurred)
Reproduction
The crash occurs while the Uno Platform Studio extension attempts to ensure .NET global tools (likely dotnet tool installation/restore logic protected by a Mutex).
Root Cause Analysis
Mutex in .NET is a thread-affine synchronization primitive:
It must be released by the exact same thread that acquired it.
It must be released exactly once per successful WaitOne.
In async code (EnsureCoreAsync), after an await, the continuation can resume on a different thread (especially without ConfigureAwait(false) or when a SynchronizationContext / TaskScheduler switches threads, which is common inside Visual Studio).
When the continuation later calls mutex.Release(), it is no longer the owning thread → ReleaseMutex fails → ApplicationException.
Suggested Fix
Replace Mutex with SemaphoreSlim (preferred for async code).
Or wrap the critical section to ensure release happens on the original thread (e.g., using SynchronizationContext capture or Task.Run on a dedicated thread).
Ensure proper try/finally around ReleaseMutex and avoid double-release paths.
Additional Context
Full debugger context and source of Mutex.cs (lines around ReleaseMutex) available in the attached diagnostic session.
This is a blocking crash for users of the Uno Studio extension inside Visual Studio.
changed the title [-]Crash: "Object synchronization method was called from an unsynchronized block of code" in DotnetGlobalToolInstaller.EnsureCoreAsync (Mutex.ReleaseMutex)[/-][+]Crash: "Object synchronization method was called from an unsynchronized block of code" in `DotnetGlobalToolInstaller.EnsureCoreAsync (Mutex.ReleaseMutex)`[/+]on Aug 30, 2026
Activity
[-]Crash: "Object synchronization method was called from an unsynchronized block of code" in DotnetGlobalToolInstaller.EnsureCoreAsync (Mutex.ReleaseMutex)[/-][+]Crash: "Object synchronization method was called from an unsynchronized block of code" in `DotnetGlobalToolInstaller.EnsureCoreAsync (Mutex.ReleaseMutex)`[/+]