Value cannot be null. Parameter name: item on application.Workbooks.Open after SaveAs call on an IWorkbook

I have code that is intended to read an Excel template, save it as another workbook, and open the new workbook.  The code is below.  It is throwing an ArgumentNullException on the second .Open, "Value cannot be null.  Parameter name: item".  I have read that code after a SaveAs to a file won't work, so I'm saving to a stream and saving that to a file. The Open still bombs.  My Syncfusion.core.dll and Syncfusion.XlsIO.Base.dll have a Version of 9.2.3.0.138 and a Runtime Version or v2.0.50727.

Code:

           string ext = System.Convert.ToString(System.IO.Path.GetExtension(_xlsTemplateFile).ToLower());
            switch (ext)
            {
                case ".xlsx":
                    application.DefaultVersion = Syncfusion.XlsIO.ExcelVersion.Excel2010;
                    break;
                case ".xlsm":
                    application.DefaultVersion = Syncfusion.XlsIO.ExcelVersion.Excel2010;
                    break;
                default:
                    application.DefaultVersion = Syncfusion.XlsIO.ExcelVersion.Excel97to2003;
                    break;
            }
            templateWorkbook = application.Workbooks.Open(_xlsTemplateFile, Syncfusion.XlsIO.ExcelParseOptions.Default);
            _xlsSaveFile = System.IO.Path.ChangeExtension(_xlsSaveFile, ext);

//templateWorkbook.SaveAs(_xlsSaveFile);
using (var mstream = new MemoryStream())
{
templateWorkbook.SaveAs(mstream);
mstream.Position = 0;  //set to beginning
using (var fstream = new FileStream(_xlsSaveFile, FileMode.OpenOrCreate))
{
mstream.CopyTo(fstream);
fstream.Flush();
}
}
            templateWorkbook.Close();
            
reportWorkbook = application.Workbooks.Open(_xlsSaveFile, ExcelOpenType.Automatic);
            templateWorkbook = null;

1 Reply

PK Prakash Kumar D Syncfusion Team October 19, 2018 06:14 AM UTC

Hi Edward, 
  
Thank you for contacting Syncfusion support. 
  
We have tried to reproduce the reported issue, but it works properly as expected. We suggest you upgrade to our latest version (16.3.0.21) of Essential Studio which has more bug fixes and enhancements which is available for download under the following link. 
  
 
If the issue persists after upgrading, please share us the code snippet along with the input Excel document which will be helpful for us to investigate further on this.  
 
Regards, 
Prakash Kumar 


Loader.
Up arrow icon