Quantcast
Channel: NetOffice - MS Office in .NET
Viewing all articles
Browse latest Browse all 1741

Created Unassigned: Workbook.ExportAsFixedFormat followed by Workbook.Close crashes the Excel app but no exception is thrown [22310]

$
0
0
When calling Workbook.ExportAsFixedFormat to save an Excel workbook as PDF quickly followed by Workbook.Close, the Excel app crashes but no exception is thrown by NetOffice.

Here's the code to reproduce the issue:
```
var s = $@"C:\users\{Environment.UserName}\desktop\test.xlsx";
var d = $@"C:\users\{Environment.UserName}\desktop\test.pdf";

var app = new Application() { Visible = true };

try
{
var wb = app.Workbooks.Open(s);
wb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, d, XlFixedFormatQuality.xlQualityMinimum, false, null, null, null, false);

// 2. Adding the sleep for at least 16ms on my machine makes it succeed.
//Thread.Sleep(20);

// 1. It crashes on the following line.
wb.Close(false);

// 3. Note that calling Close on the COM object works and properly closes the workbook.
//((dynamic)wb.UnderlyingObject).Close(false);

Console.WriteLine("Done");
}
catch (Exception ex)
{
ex.Dump();
}
finally
{
app.Quit();
app.Dispose();
}
```

Some more details.
1. On my machine, it crashes the Excel app when the code executes in 1.02s or less.
2. On my machine (or on slower machines), it doesn't crash the Excel app when the code executes in 1.1s or more.
3. Calling the Close method on the COM object itself doesn't crash the Excel app.

I'm using NetOffice 1.7.3.0 on Windows 10 Enterprise Anniversary Update, 64-bit. I used LINQPad to reproduce the scenario above.

I have uploaded the LINQPad query (if needed). The Excel file (test.xlsx) is a very simple workbook with "Hello World1" in the first cell.

Viewing all articles
Browse latest Browse all 1741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>