4

我尝试通过 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
4

4 回答 4

9

似乎将 ApplicationPool 的 Identity 更改为 LocalSystem 并不总是有帮助,这在我的情况下是 Windows Server 2009 R2。奇怪的是,自从我阅读了这个主题并解决了基于 OpenXML 的大型报告的问题以来,它工作了大约半年,但几天前它就停止了工作。

因此,经过一天的研究,我发现另外在 ApplicationPool 的高级设置中将加载用户配置文件设置为True(默认值为 False)并且再次没有问题。

于 2015-07-21T12:04:36.503 回答
3

我将应用程序池标识更改为在 IIS 中具有完全控制访问权限的更高级别帐户。

IIS>应用程序池>高级设置>身份(在进程模式下)>选择具有更高访问权限的帐户

于 2013-10-19T14:23:55.017 回答
3

我同意@Behrooz,将 ApplicationPool 的Identity更改为LocalSystem,它会起作用。

当项目在我的 PC 的本地主机上运行时,我没有这个问题,但是当我将它部署到服务器时,我做到了。

看这个截图:

在此处输入图像描述

于 2015-05-05T16:31:07.263 回答
0

OpenXML 对大文件使用独立存储。更多信息请访问http://www.lyquidity.com/devblog/?p=65

您可以在 C:\Users\username\AppData\Local 中找到 isolatedStorage 文件夹。我们发现,当这个文件夹为时,我们没有收到“无法创建互斥锁”异常。在我们重新启动 IIS之后,我们也没有立即得到异常。我们发现它必须与使用和锁定该文件夹的其他 Web 应用程序有关,因此 OpenXml 的互斥锁异常。

经过更多搜索,我们发现 DotNetOpenAuth 也可能根据https://github.com/DotNetOpenAuth/DotNetOpenAuth/issues/381使用隔离存储,因为它的报告功能。我们的一些应用程序正在使用它,当它们启动时,它们会在 IsolatedStorage 文件夹中创建文件和文件夹,之后 Mutex 异常就会开始发生。

您可以通过在 Web.config 中将以下标志更改为 false 来禁用 DotNetOpenAuth 报告

<reporting enabled="true"/>

这为我们解决了

于 2019-11-01T15:23:02.607 回答