OpenXml and Unable to create mutex

3

I tried to create Excel document through openXml lib, but when i wanna create Excel from large number of data, server shoe me Unable to create mutex. (Exception from HRESULT: 0x80131464) error, the stack trace is :

[IsolatedStorageException: Unable to create mutex. (Exception from HRESULT: 0x80131464)]
   System.IO.IsolatedStorage.IsolatedStorageFile.Open(String infoFile, String syncName) +0
   System.IO.IsolatedStorage.IsolatedStorageFile.Lock(Boolean& locked) +370
   System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf) +468
   System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile isf) +35
   MS.Internal.IO.Packaging.SafeIsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, ReliableIsolatedStorageFileFolder folder) +102
   MS.Internal.IO.Packaging.PackagingUtilities.CreateUserScopedIsolatedStorageFileStreamWithRandomName(Int32 retryCount, String& fileName) +276
   MS.Internal.IO.Packaging.SparseMemoryStream.EnsureIsolatedStoreStream() +31
   MS.Internal.IO.Packaging.SparseMemoryStream.SwitchModeIfNecessary() +400
   MS.Internal.IO.Packaging.CompressEmulationStream.Write(Byte[] buffer, Int32 offset, Int32 count) +76
   MS.Internal.IO.Packaging.CompressStream.Write(Byte[] buffer, Int32 offset, Int32 count) +431
   MS.Internal.IO.Zip.ProgressiveCrcCalculatingStream.Write(Byte[] buffer, Int32 offset, Int32 count) +177
   MS.Internal.IO.Zip.ZipIOModeEnforcingStream.Write(Byte[] buffer, Int32 offset, Int32 count) +130
   System.Xml.XmlUtf8RawTextWriter.FlushBuffer() +7519035
   System.Xml.XmlUtf8RawTextWriter.RawText(Char* pSrcBegin, Char* pSrcEnd) +232
   System.Xml.XmlUtf8RawTextWriter.WriteStartElement(String prefix, String localName, String ns) +192
   System.Xml.XmlWellFormedWriter.WriteStartElement(String prefix, String localName, String ns) +7517920
   DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter) +283
   DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w) +114
   DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter) +316
   DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w) +114
   DocumentFormat.OpenXml.OpenXmlPartRootElement.WriteTo(XmlWriter xmlWriter) +404
   DocumentFormat.OpenXml.OpenXmlPartRootElement.SaveToPart(OpenXmlPart openXmlPart) +217
   DocumentFormat.OpenXml.Packaging.OpenXmlPackage.SavePartContents() +203
   DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Dispose(Boolean disposing) +32
   DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Dispose() +24
   Yara.Evento.Utility.Office.Excel.Write.Do(List`1 objects, String sheetName, HeaderList headerNames) +2371
   Yara.Evento.Management.Web.Controllers.TicketController.List(String button, Nullable`1 page, String startDate, String endDate, String ownerMail, String eventName, String mobile, String eMail, String ticketCode, Int32 sort, Boolean desc, Int32 eventId, Int32 status, Int32 variantId) +13628
   lambda_method(Closure , ControllerBase , Object[] ) +864
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +264
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +124
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +726390
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +309
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +726324
   System.Web.Mvc.Controller.ExecuteCore() +159
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +334
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +15
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +52
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
c#
.net
excel
ms-office
openxml
asked on Stack Overflow Oct 19, 2013 by Behrooz

4 Answers

8

It also seems that changing ApplicationPool's Identity to LocalSystem does not always help which was in my case with Windows Server 2009 R2. The strange thing is that it worked for about half a year since I have read this topic and fixed my problem with large OpenXML-based reports but several days ago it just stopped working.

So after a day of research I found that additionally in ApplicationPool's Advanced Settings set Load User Profile to True (default value was False) and no problems again.

answered on Stack Overflow Jul 21, 2015 by Sergii
2

I change application pool Identity to higher level account with full control access in IIS.

IIS> application pools>advanced setting>Identity (in process mode)>choose an account with higher access

answered on Stack Overflow Oct 19, 2013 by Behrooz
2

I agree with @Behrooz, change the the ApplicationPool's Identity to LocalSystem and it will work.

I didn't have this problem when the project was running on my PC's local host, but I did when I deployed it to the Server..

See this screenshot:

enter image description here

answered on Stack Overflow May 5, 2015 by t_plusplus
0

OpenXML uses IsolatedStorage for large file sizes. More info at http://www.lyquidity.com/devblog/?p=65

You can find isolatedStorage folder in C:\Users\username\AppData\Local. What we found was that when this folder was empty we weren't getting the "Unable to create Mutex" exception. We also weren't getting the exception right after we would restart our IIS. We figured out it's got to be something to do with other web apps using and locking that folder, hence the mutex exception from OpenXml.

After more searching we found that DotNetOpenAuth might also be using Isolated storage as per https://github.com/DotNetOpenAuth/DotNetOpenAuth/issues/381 for it's reporting feature. Some of our apps were using it and the moment they started up they would create files and folders in the IsolatedStorage folder after which the Mutex exception would start happening.

You can disable DotNetOpenAuth reporting by changing the following flag to false in your Web.config

<reporting enabled="true"/>

This fixed it for us

answered on Stack Overflow Nov 1, 2019 by FabianDev

User contributions licensed under CC BY-SA 3.0