[英]OpenXml and Unable to create mutex
我試圖通過 openXml lib 創建 Excel 文檔,但是當我想從大量數據創建 Excel 時,服務器鞋我無法創建互斥鎖。 (來自 HRESULT 的異常:0x80131464)錯誤,堆棧跟蹤是:
[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
似乎將 ApplicationPool 的標識更改為 LocalSystem 並不總是有幫助,這在我使用 Windows Server 2009 R2 的情況下。 奇怪的是,自從我閱讀了這個主題並用基於 OpenXML 的大型報告解決了我的問題后,它工作了大約半年,但幾天前它剛剛停止工作。
因此,經過一天的研究,我發現另外在 ApplicationPool 的高級設置中將加載用戶配置文件設置為True (默認值為 False)並且再次沒有問題。
我將應用程序池標識更改為在 IIS 中具有完全控制訪問權限的更高級別帳戶。
IIS> 應用程序池> 高級設置> 身份(進程模式)> 選擇具有更高訪問權限的帳戶
我同意@Behrooz,將ApplicationPool 的身份更改為LocalSystem ,它將起作用。
當項目在我的 PC 的本地主機上運行時我沒有遇到這個問題,但是當我將它部署到服務器時我遇到了。
看這個截圖:
OpenXML 對大文件使用隔離存儲。 更多信息請訪問http://www.lyquidity.com/devblog/?p=65
您可以在 C:\\Users\\username\\AppData\\Local 中找到孤立存儲文件夾。 我們發現,當此文件夾為空時,我們不會收到“無法創建互斥鎖”異常。 在我們重新啟動 IIS后,我們也沒有立即得到異常。 我們發現這與使用和鎖定該文件夾的其他 Web 應用程序有關,因此來自 OpenXml 的互斥鎖異常。
經過更多搜索,我們發現 DotNetOpenAuth 也可能根據https://github.com/DotNetOpenAuth/DotNetOpenAuth/issues/381使用隔離存儲來實現其報告功能。 我們的一些應用程序正在使用它,當它們啟動時,它們會在 IndependentStorage 文件夾中創建文件和文件夾,之后 Mutex 異常將開始發生。
您可以通過在 Web.config 中將以下標志更改為 false 來禁用 DotNetOpenAuth 報告
<reporting enabled="true"/>
這為我們修復了它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.