Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 6013 [details]
unit test which reproduces the problem
Got a real strange problem with xml serialisation.
Super simple test class with only one boolean property. When I set and read once everything works fine. If I set and reset from false to true the serializer will add an extra '>' to the end of the file which makes it unreadable.
Output looks like this:
<?xml version="1.0" encoding="utf-8"?>
<UserDefaults xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
It's an iOS project so I don't know if it's only happening there.
The attached unit test shows the problem. Tests Test1 and Test2 work fine. Test3 fails.
I also tried with a string property and used null and "true" as pseudo bools and everything works fine then. So it seems to be related to the property type.
I can reproduce this on the desktop edition of Mono as well.
mcs -target:library a.cs -r:/cvs/monodevelop/main/src/addins/NUnit/lib/nunit.core.dll -r:/cvs/monodevelop/main/src/addins/NUnit/lib/nunit.framework.dll
MONO_PATH=/cvs/monodevelop/main/src/addins/NUnit/lib/ nunit-console a.dll
This is not a bug in Mono. The problem is that File.OpenWrite() doesn't truncate the file, so in Test3, when you write the file for the second time, you are overwriting the contents of the previous save, but the already existing file is larger (1 char larger), so a dangling '>' from the previous save is left.
From the MS docs about File.OpenWrite():
" For an existing file, it does not append the new text to the existing text. Instead, it overwrites the existing characters with the new characters. If you overwrite a longer string (such as “This is a test of the OpenWrite method”) with a shorter string (such as “Second run”), the file will contain a mix of the strings (“Second runtest of the OpenWrite method”). "