This project is read-only.

Weird behaviour trying to read an excel file

Apr 1, 2011 at 9:07 AM
Edited Apr 1, 2011 at 9:31 AM

when trying to open for reading one specific excel file, it gives me the following error: 

Cannot access a disposed object.

 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ObjectDisposedException: Cannot access a disposed object.

Source Error:

Line 205:        {
Line 206:            _stream = stream;
Line 207:            _workbook = new HSSFWorkbook(_stream, true);
Line 208:            _sheet = _workbook.GetSheetAt(0);
Line 209:            _enumerator = _sheet.GetRowEnumerator();

Source File: D:\Projects\ABCD\ABCD.Model\Excel\NpoiExcelReader.cs    Line: 207

Stack Trace:

[ObjectDisposedException: Cannot access a disposed object.]
   System.Security.Cryptography.HashAlgorithm.ComputeHash(Byte[] buffer) +2593147
   NPOI.HSSF.Record.Crypto.Biff8EncryptionKey.CreateKeyDigest(String password, Byte[] docIdData) +552
   NPOI.HSSF.Record.Crypto.Biff8EncryptionKey.Create(Byte[] docId) +66
   NPOI.HSSF.Record.StreamEncryptionInfo.CreateDecryptingStream(Stream original) +150
   NPOI.HSSF.Record.RecordFactoryInputStream..ctor(Stream in1, Boolean shouldIncludeContinueRecords) +273
   NPOI.HSSF.Record.RecordFactory.CreateRecords(Stream in1) +133
   NPOI.HSSF.UserModel.HSSFWorkbook..ctor(DirectoryNode directory, POIFSFileSystem fs, Boolean preserveNodes) +303
   NPOI.HSSF.UserModel.HSSFWorkbook..ctor(POIFSFileSystem fs, Boolean preserveNodes) +76
   NPOI.HSSF.UserModel.HSSFWorkbook..ctor(Stream s, Boolean preserveNodes) +78
   Mefis.Model.Excel.NpoiExcelReader..ctor(Stream stream) in D:\Projects\Mefis2\Mefis.Model\Excel\NpoiExcelReader.cs:207
   Mefis.Model.Excel.NpoiExcelReader.CreateReader(Stream stream) in D:\Projects\Mefis2\Mefis.Model\Excel\NpoiExcelReader.cs:222
   Mefis.Model.Excel.BaseImportReader.ParseFile(Stream stream) in D:\Projects\Mefis2\Mefis.Model\Excel\BaseImportReader.cs:234
   Mefis.Web.Controllers.BudgetReportController.ImportBudgetReportT2(Nullable`1 budgetScheduleId, Nullable`1 eBKActivityId, String tab) in D:\Projects\Mefis2\Mefis.Web\Controllers\BudgetReportController.cs:228
   lambda_method(Closure , ControllerBase , Object[] ) +280
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +51
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +409
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +52
   System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +127
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
   System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
   System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
   System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +305
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830
   System.Web.Mvc.Controller.ExecuteCore() +136
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +111
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +65
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +42
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +52
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8841105
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

 

 

any ideas what could be the problem ?

EDIT: i forgot to mention that  i am using NPOI.dll, v2.0.50727

Coordinator
Apr 1, 2011 at 6:50 PM

It looks _workbook or _stream is already disposed. Is it possible that you already called Dispose() explicitly last time?

Apr 4, 2011 at 9:46 AM

nope.

and the problem occurs when i try to read one specific excel file, when reading others there are no problems.

Coordinator
Apr 5, 2011 at 11:16 AM

Can you send me the xls? my email is tonyqus (at) gmail.com

Coordinator
Apr 8, 2011 at 5:02 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.