Semaphore exception - Adding the specified count to the semaphore would cause it to exceed its maximum count

In my case, the problem was that I stopped the application while debugging. The application was making a lot of async callings.

So I reset my IIS server: iisreset via Command Prompt or PowerShell, and it worked.

EDIT: Look at the @aaroncatlin comment for IIS Express


I think that this may be a solution to the problem: http://www.davepaquette.com/archive/2013/03/27/managing-entity-framework-dbcontext-lifetime-in-asp-net-mvc.aspx - as you can see there, it is essential to take care for disposal of the DbContext when it´s lifetime is over.

Remember, Db connections end up in unmanaged db handling code, so the problem is unless garbage collection disposes the context it stays sleeping in the main memory, thereby also blocking a connection from the connection pool. So sooner or later, under the right conditions, you empty the connection pool and get your exception.