Throw ObjectDisposedException if one tries to operate with a disposed workbook
See original GitHub issueRead and complete the full issue template
Do you want to request a feature or report a bug?
- Bug
- Feature
- Question
Did you test against the latest CI build?
- Yes
- No
Version of ClosedXML
e.g. 0.95.3
What is the current behavior?
There was a number of bug reports related to unpredictable behavior when the workbook is accessed after it’s been disposed.
https://github.com/ClosedXML/ClosedXML/issues/1243#issuecomment-585938206 https://github.com/ClosedXML/ClosedXML/issues/1306 https://github.com/ClosedXML/ClosedXML/issues/1491
This is, of course, wrong, but it takes long investigations for the users to nail down the root cause, apparently.
What is the expected behavior or new feature?
The suggestion is to throw ObjectDisposedException
each time one tries to operate with a disposed workbook.
See this thread https://github.com/ClosedXML/ClosedXML/issues/1306#issuecomment-597616529
It may break someone’s code, of course, but I think immediately fail is better than have unreliable code with a hidden bug.
Reproducibility
static void Main(string[] args)
{
using (var ms = new MemoryStream())
{
var wb = CreateWorkbook();
wb.SaveAs(ms);
var wb2 = new XLWorkbook(ms);
Console.WriteLine(wb2.Worksheet("Test").FirstCell().Value); // <- String.Empty
}
Console.ReadKey();
}
private static XLWorkbook CreateWorkbook()
{
using (var wb = new XLWorkbook())
{
var ws = wb.AddWorksheet("Test");
ws.FirstCell().Value = "Good buy cruel world";
return wb;
}
}
- I attached a sample spreadsheet. (You can drag files on to this issue)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
“If something seems too good to be true, it probably is too good to be true.”
Wow, it looks great!