Share via


System.InvalidOperationException: Mutex could not be created.

We've seen a few of these issues come through lately andwanted to get something posted so people can find it.

If you created a custom account to run the process that ASP.NET is running in, you may encounter the following exception:

System.InvalidOperationException: Mutex could not be created.Stack Trace: [InvalidOperationException: Mutex could not be created.] System.Web.Compilation.CompilationMutex..ctor(String name, String comment) +3464689 System.Web.Compilation.CompilationLock..cctor() +158

[TypeInitializationException: The type initializer for 'System.Web.Compilation.CompilationLock' threw an exception.] System.Web.Compilation.CompilationLock.GetLock(Boolean& gotLock) +32 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +114

[HttpException (0x80004005): The type initializer for 'System.Web.Compilation.CompilationLock' threw an exception.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +3426871 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +88 System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +149--------------------------------------------------------------------------------Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

Note: The error will appear to be random, but once it appears, will remain until a reboot or until the handles to the mutex are closed.

Cause:
======
This occurs because the permissions on the following registry key no longer have your custom account:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\2.0.50727.0\CompilationMutexName

The compilation mutex gets it's permissions from this registry key and with your custom account missing, the process running ASP.NET cannot get a handle to the mutex and fails during compilation.

Resolution:=========

  1. Run the following to add your custom account to the registry key permissions:
             ASPNET_regiis -ga domain\account.
  2. Either restart the server or close the handles to the mutex (see below)

To close the handles to the Mutex:

  1. Download and launch Process Explorer from www.sysinternals.com
  2. From the Find menu, select Find Handle or DLL
  3. In the Handle or DLL substring box, type “mutant” (without quotes) and click Search
  4. Click the Handle or DLL column heading to sort the items and find a mutex that starts with CL. The handle will typically be devenv.exe (the IDE for Visual Studio) and aspnet_wp.exe or w3wp.exe. The handle will look similar to:
  5. \BaseNameObjects\CLbdd6aa8f
  6. Select the handle in the search box and Process Explorer locates the Process and the handle in the main window
  7. Right-click the handle in the main window and select Close Handle

Additional Info:
============
The error may occur anytime you run ASP.NET as a custom account and the above mentioned registry key does not have the account listed in the permissions.

If you receive the error and you are running with a custom account on IIS 6 in worker process mode (code running in w3wp.exe), you can add your custom account to the IIS_WPG group on the server. The IIS_WPG group is granted access to the registry key by default.

Comments

  • Anonymous
    September 29, 2006
    Way behind on posting and cleaning out the inbox, but wanted to capture this information.  Just got a new laptop at work (which is part of the reason I'm so far behind) and as is the norm you end up...

  • Anonymous
    March 22, 2007
    Today I was stuck for the first time with this: System.InvalidOperationException: Mutex could not be

  • Anonymous
    May 07, 2007
    Mutex could not be created 的异常错误解决办法

  • Anonymous
    May 11, 2007
    The comment has been removed

  • Anonymous
    June 21, 2007
    The comment has been removed

  • Anonymous
    July 14, 2007
    1、 当前标识(NT AUTHORITYNETWORK SERVICE)没有对“C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary

  • Anonymous
    August 03, 2007
    正解: http://blogs.msdn.com/jorman/archive/2006/07/24/system-invalidoperationexception-mutex-could-not-be-created.aspx 1) C:WINDOWSMicrosoft.NETFrameworkv2.0.50727ASPNET_regiis -ga yourdomainyouraccount 2) iisreset

  • Anonymous
    October 03, 2007
    On the recommendation of a trusted co-worker who shall remain unnamed, I had installed the March CTP

  • Anonymous
    February 16, 2008
    To clean up an old farm from some setup errors, I recently rebuilt the farm from bare metal, re-attaching

  • Anonymous
    February 16, 2008
    To clean up an old farm from some setup errors, I recently rebuilt the farm from bare metal, re-attaching

  • Anonymous
    September 06, 2011
    about Error: "unable to start debugging on the web server" & "System.InvalidOperationException: Mutex could not be created." Thank you for the solution. I tried your solution (In this page) , It was OK but assume that there is a program that is using port 80, then IIS could not work correctly finding the program using port 80 and uninstall that program is better solution.