Description
Description
After constructing with XamlXmlReader(string, XamlXmlReaderSettings)
, reading with it and disposing it...
If you try to open the same file for write you get an IOException "The process cannot access the file ... because it is being used by another process."
Same issue for the XamlXmlReader(Stream, XamlXmlReaderSettings)
form.
Even when you specify CloseInput=true
on the XamlXmlReaderSettings
Reproduction Steps
Precondition: You need a Test.xaml file for it to read from
var testFile = "Test.xaml";
var settings = new XamlXmlReaderSettings()
{
// Actually want other settings here like ProvideLineInfo = true
CloseInput = true
};
using (var reader = new XamlXmlReader(testFile, settings))
{
// Read something to ensure it has opened things
var firstRead = reader.Read();
}
// XamlXmlReader was Disposed. It should be safe to open the same file for write.
using var readStream = File.OpenWrite(testFile);
Attaching a sample Test.xaml.txt file (because it won't let me upload a .xaml file) - rename it to Test.xaml to use it.
Test.xaml.txt
Expected behavior
With these constructor forms, once the XamlXmlReader is Disposed, user should be able to open the same file for write.
Actual behavior
With these constructor forms, once the XamlXmlReader is Disposed, an exception occurs when the user tries to open the same file for write.
Regression?
No response
Known Workarounds
Instead user does
- creates a Stream themselves,
- pass that to XamlXmlReader constructor (ideally with XamlXmlReaderSettings.CloseInput = false in case this issue gets fixed)
- Dispose of XamlXmlReader
- Dispose of the Stream themselves.
Configuration
.NET 6
(specific cases tested on net6.0-windows, x64, running on Windows 10 but not sure any of these are relevant)
Other information
I think property XamlXmlReaderSettings.CloseInput doesn't apply to the first form (taking a string filePath), as nothing else can possibly close whatever the reader used internally to read - so it should always close on Dispose.
Although a different class, it also seems analagous to XmlReaderSettings.CloseInput, which says the same.
The property should apply to the second form (taking a Stream argument), but seems to be ineffective there too.