2015-10-20 71 views
1

在IIS7 Windows2008计算机上有一个MVC4应用程序。该应用程序将作为ApplicationPoolIdentity运行,并且相应的用户可以访问ProgramData \ IsolatedStorage文件夹。 它也具有C:\ Documents and Settings \ Default User \ Local Settings \ Application Data \ IsolatedStorage文件夹的权限。 但在使用openxml编写大型excel文件时仍然会收到异常。System.ObjectDisposedException:存储必须为此操作打开

ERROR MHDB.MvcApplication - System.ObjectDisposedException: Store must be open for this operation. 
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf) 
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile isf) 
at MS.Internal.IO.Packaging.PackagingUtilities.SafeIsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, ReliableIsolatedStorageFileFolder folder) 
at MS.Internal.IO.Packaging.PackagingUtilities.CreateUserScopedIsolatedStorageFileStreamWithRandomName(Int32 retryCount, String& fileName) 
at MS.Internal.IO.Packaging.SparseMemoryStream.EnsureIsolatedStoreStream() 
at MS.Internal.IO.Packaging.SparseMemoryStream.SwitchModeIfNecessary() 
at MS.Internal.IO.Packaging.CompressEmulationStream.Write(Byte[] buffer, Int32 offset, Int32 count) 
at MS.Internal.IO.Packaging.CompressStream.Write(Byte[] buffer, Int32 offset, Int32 count) 
at MS.Internal.IO.Zip.ProgressiveCrcCalculatingStream.Write(Byte[] buffer, Int32 offset, Int32 count) 
at MS.Internal.IO.Zip.ZipIOModeEnforcingStream.Write(Byte[] buffer, Int32 offset, Int32 count) 
at System.Xml.XmlUtf8RawTextWriter.FlushBuffer() 
at System.Xml.XmlUtf8RawTextWriter.RawText(Char* pSrcBegin, Char* pSrcEnd) 
at System.Xml.XmlUtf8RawTextWriter.WriteEndElement(String prefix, String localName, String ns) 
at System.Xml.XmlWellFormedWriter.WriteEndElement() 
at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w) 
at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter) 
at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w) 
at DocumentFormat.OpenXml.OpenXmlElement.WriteTo(XmlWriter xmlWriter) 
at DocumentFormat.OpenXml.OpenXmlCompositeElement.WriteContentTo(XmlWriter w) 
at DocumentFormat.OpenXml.OpenXmlPartRootElement.WriteTo(XmlWriter xmlWriter) 
at DocumentFormat.OpenXml.OpenXmlPartRootElement.SaveToPart(OpenXmlPart openXmlPart) 
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.SavePartContents() 
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Dispose(Boolean disposing) 
at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Dispose() 
at BL.OpenXML.Export(DataTable dt, Stream fs, Boolean createNewDocument) 
at BL.BusinessLogic.CreateOpReport(UnitOfWork uow, String user, String orgapath, List`1 orgaids, Boolean isfin, String cycle, String startperiod, String endperiod) 
at MHDB.Controllers.HomeController.GetFileAsStream() 
at MHDB.Controllers.HomeController.ExportExcel() 
at lambda_method(Closure , ControllerBase , Object[]) 
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) 
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass13.<InvokeActionMethodWithFilters>b__10() 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) 
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) 
at System.Web.Mvc.Controller.ExecuteCore() 
at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) 
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0() 
at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) 
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) 
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

感谢您的帮助!

回答

0

由于System.IO.Packaging在内部写入大于10MB的文件时,它将不再将数据临时保存在内存中,直到下次保存时才会切换到独立存储。这本身可能会导致很多问题,因为IsolateStorage并不意味着与同一应用程序的多个线程/多个实例一起使用,您也可能会遇到一些权限问题。

考虑到这是一个web应用程序,我认为这可能涉及到在同一时间多个用户的写作,但都被解析到相同的独立存储位置..

我已经在这个问题的相同的多个实例绊倒应用程序都被解析到相同的位置。我仍然在寻找一个完美的解决方案,但我还是能够迫使每个实例解析为一个不同的IsolatedStorage位置,并使用该唯一:

var rootDirUserField= typeof(IsolatedStorageFile).GetField("s_RootDirUser", BindingFlags.NonPublic | BindingFlags.Static); 
rootDirUserField.SetValue(null, "<unique location in isolated storage>"); 

这工作,因为静电场IsolatedStorageFile.s_RootDirUser在使用解析要使用的新目录。我的修复程序特定于用户|域|装配范围。

我很想获得更好的解决方案来解决这个问题。

+1

请看我得到这个问题的答案。我希望我的问题和你的问题一样。 http://stackoverflow.com/questions/35922941/store-must-be-open-for-this-operation-system-io-packaging-package?noredirect=1#comment59504725_35922941 –

+0

嗨。感谢这另一个链接。我想我会用新的Packaging命名空间来构建我自己的开放式xml sdk – pillesoft

相关问题