Bug 28017 - NameTable.Add(Char[], int, int) throwing wrong/inconsistent exception
Summary: NameTable.Add(Char[], int, int) throwing wrong/inconsistent exception
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-13 14:38 UTC by nader
Modified: 2015-03-17 17:03 UTC (History)
3 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-13 14:38:30 UTC
It appears that System.Xml.NameTable.Add(Char[], int, int) throws wrong/inconsistent exceptions
when called with an invalid 2nd and 3rd arugments. More specifically, when calling NameTable.Add with a negative integer arguments, Xamarin Android throws an ArugmentOutOfRangeException . While
.Net and Windows Phone 8.1 both throw an IndexOutOfRangeException. 

The msdn documentation lists both exceptions as possibilities while making this
call. However, it seems based on the exception.Message in Xamarin Android and the fact that Microsoft's implementation is throwing IndexOutOfRangeException, it seems that the correct Exception type should be IndexOutOfRangeException

To reproduce this issue, run the following code snippet:

System.Xml.NameTable v0 =  new System.Xml.NameTable();
System.Char v5 = '0';
System.Char[] v6 =  new System.Char[] {v5};
System.Int32 v7 = (System.Int32)(-2);
System.Int32 v8 = (System.Int32)(-3);
System.String v9 = ((System.Xml.NameTable)v0).Add((System.Char[])v6, (System.Int32)v7, (System.Int32)v8) ;

Windows result: IndexOutOfRangeException thrown
exception.Message = "Index was outside the bounds of the array"
Xamarin Android result: ArugmentOutOfRangeException 
exception.Message = "Cannot be negative.\nParameter name: startIndex"

If you look at the MSDN documentation (https://msdn.microsoft.com/en-us/library/y3wy38a8(v=vs.110).aspx)
it states that and IndexOutOfRangeException should be thrown when the second argument (start) is negative.
The Xamarin Android Exception message mentions this "Cannot be negative.\nParameter name: startIndex" but the type
of the exception thrown doesn't match the documentation.

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.

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 Atsushi Eno 2015-03-17 17:03:48 UTC
Now our NameTable is based on referencesource, even this trivial difference is also gone.