Bug 17671 - XmlSerializer produces invalid XML (duplicated ending '>') for bool properties
Summary: XmlSerializer produces invalid XML (duplicated ending '>') for bool properties
Status: RESOLVED INVALID
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: unspecified
Hardware: Other Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Lluis Sanchez
URL:
Depends on:
Blocks:
 
Reported: 2014-02-09 12:50 UTC by daniel.doubleday
Modified: 2014-02-12 03:50 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
unit test which reproduces the problem (2.76 KB, text/plain)
2014-02-09 12:53 UTC, daniel.doubleday
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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.

Related Links:
Status:
RESOLVED INVALID

Description daniel.doubleday 2014-02-09 12:50:25 UTC

    
Comment 1 daniel.doubleday 2014-02-09 12:53:28 UTC
Created attachment 6013 [details]
unit test which reproduces the problem
Comment 2 daniel.doubleday 2014-02-09 12:59:05 UTC
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">
  <AutoSave>true</AutoSave>
</UserDefaults>>

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.
Comment 3 daniel.doubleday 2014-02-09 13:01:14 UTC
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.
Comment 4 Miguel de Icaza [MSFT] 2014-02-11 21:44:51 UTC
I can reproduce this on the desktop edition of Mono as well.

Command line:

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
Comment 5 Lluis Sanchez 2014-02-12 03:50:55 UTC
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”). "