Bug 28123 - Inconsistent behavior in System.Xml.XmlReaderSettings.MaxCharactersInDocument
Summary: Inconsistent behavior in System.Xml.XmlReaderSettings.MaxCharactersInDocument
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 3.10.0
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-03-17 14:31 UTC by nader
Modified: 2015-03-17 17:07 UTC (History)
4 users (show)

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

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:

Description nader 2015-03-17 14:31:10 UTC
It appears that setting MaxCharactersInDocument property to a negative value in 
System.Xml.XmlReaderSettings class in Xaramin Android and mono 3.3.0 results in inconsistent behavior when
compared to Windows phone 8.1 and .Net 4.5. In .Net, trying to set this property to a negative value results in an
ArgumentOutOfRangeException. However, in mono, so such exception is thrown and the property successfully is set to a negative value. Since this property denotes the maximum allowable number of character in an XML document, it seems the .Net behavior of not allowing a negative value to be more plausible.

To reproduce this issue, run the following code snippet:

    System.Xml.XmlReaderSettings v0 =  new System.Xml.XmlReaderSettings();
    ((System.Xml.XmlReaderSettings)v0).MaxCharactersInDocument = -10 ;
catch (System.ArgumentOutOfRangeException e)
    return 0;
return -1;

Windows Phone 8.1/ .Net 4.5 result: 
returns 0
exception.Message = 
"Specified argument was out of the range of valid values.
Parameter name: value"

Xamarin Android/Mono 3.3.0 result: 
reutrns -1
No exceptions are thrown

This code snippet was placed in a PCL project and was run on an android 4.4.2
emulator and a Windows Phone 8.1 emulator and .Net 4.5 on the Desktop. 
Additionally, the code snippet was compiled using mono 3.3.0, which matched the Xamarin android behavior.

Additional Build Environment info:
Xamarin.Android Version: 4.16.0 (Business Edition)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39
Comment 1 Jonathan Pryor 2015-03-17 15:53:05 UTC
Also repros in `csharp`:

$ csharp -r:System.Xml
csharp> using System.Xml;
csharp> var s = new System.Xml.XmlReaderSettings();
csharp> s.MaxCharactersInDocument = -10;

No exception is generated.
Comment 2 Atsushi Eno 2015-03-17 17:07:19 UTC
Now our XmlReaderSettings is based on referencesource, even this no-one-would-actually-depend-on-it kind of difference is also gone. It was even documented as MonoTODO.