I have a very simple ASP.Net Core MVC app with a button that call a method in a class library in order to create a SpreadsheetDocument from randomly-generated integer values. When I run the app in Visual Studio 2017 with a single breakpoint that is hit once for each column of data I get the entire, valid, Excel file downloaded and it opens and displays perfectly. If I remove the breakpoint and run the app the file is created and downloaded but the columns are identical. I could really use some advice on this. Here is the MVC Controller method:
publicIActionResultIndex(){// Create an instance of the CreateExcel class.var createExcel =newCreateExcel();// Create a new Excel spreadsheet MemoryStream.var excelSpreadsheet = createExcel.FetchNewMemorySpreadsheet();// Return the spreadsheet.returnFile(excelSpreadsheet,"application/vnd.ms-excel","Report.xlsx");}
Here is the method that oversees the creation of the SpreadsheetDocument:
publicStreamFetchNewMemorySpreadsheet(){// Declare the object to return from the method.SpreadsheetDocument spreadsheet =null;//try{// Make sure that the MemoryStream is valid.if(_memStream ==null) _memStream =newMemoryStream();// Create a SpreadsheetDocument. spreadsheet =CreateSpreadsheetWorkbook(_memStream);// Create a Stylesheet.CreateStylesheet(spreadsheet);// Add static data to the spreadsheet.FillSpreadsheet(spreadsheet);// Close the document. spreadsheet?.Close();// Ensure that we have some data in the MemoryStream.if(_memStream?.Length>0){// Seek to the beginning of the stream. _memStream.Seek(0,SeekOrigin.Begin);}// Return the stream.return _memStream;}catch(Exception e){throw;}finally{// If the Spreadsheet is not null, call it's Dispose method. spreadsheet?.Dispose();}}
Since the anomaly only occurs when I run without any breakpoints, I suspect that the problem might have something to do with the MemoryStream OR because I am not using some kind of asynchronous call.
HELP! PLEASE!
Thanks