2015-10-20 70 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

相關問題