Bug 27922 - XmlConvert.ToUint() throwing wrong/inconsistent exception
Summary: XmlConvert.ToUint() throwing wrong/inconsistent exception
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.16.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Ankit Jain
URL:
Depends on:
Blocks:
 
Reported: 2015-03-11 15:51 UTC by nader
Modified: 2015-03-16 09:31 UTC (History)
2 users (show)

Tags:
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 Developer Community or GitHub 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 FIXED

Description nader 2015-03-11 15:51:32 UTC
It appears that XmlConvert.ToUint16/32/64 throw wrong/inconsistent exception when called with an invalid argument. More specifically, when calling XmlConvert.ToUint32("-1") Xamarin Android throws an OverflowException. While .Net and Windows Phone 8.1 both throw a FormatExcetion. 

The msdn documentation lists both exceptions as possibilities while making this call. However, it seems FormatException to take precedence over OverflowException. 

To reproduce, run the following code snippet:

System.Double v2 = (System.Double)(-1);
System.String v3 = System.Xml.XmlConvert.ToString((System.Double)v2) ;
System.UInt32 v4 = System.Xml.XmlConvert.ToUInt32((System.String)v3) ;

Windows result: FormatException thrown
Xamarin Android result: OverflowException

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 Udham Singh 2015-03-13 12:57:40 UTC
I have checked this issue and observed that we are getting exception 'FormatException' for console application and exception 'OverflowException' for android application. 

To reproduce this issue I have created a simple android app and a console app, and implement the code given in bug description in both the apps, and got the exception when I run the app.

Application Output for Android app : https://gist.github.com/Udham1/8e9dcd7d186d07a2cbce
Exception Log for console app : https://gist.github.com/Udham1/dd791e8687c2ca2cad6c
Ide Log : https://gist.github.com/Udham1/09b800944ff81c64f304

Screencast : http://www.screencast.com/t/V7cZng68

Environment Info :

=== Xamarin Studio ===

Version 5.9 (build 214)
Installation UUID: 1acc211c-3883-4e33-b4d2-ad3b5d55c2c8
Runtime:
	Microsoft .NET 4.0.30319.18449
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

=== Xamarin.Android ===

Version: 5.1.0 (Business Edition)
Android SDK: D:\Backup_OldMachine\D Drive\SDK\SDK\android-sdk
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: C:\Program Files\Java\jdk1.7.0_67
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Version: 0.2.5
Location: C:\Program Files\Xamarin Android Player\DeviceManager.exe

=== Build Information ===

Release ID: 509000214
Git revision: 1cd56e8fd54e4884caf1d509d793cbaf386b606d
Build date: 2015-03-13 08:29:20-04
Xamarin addins: d5276b9c69b0cc42f2bac6f30f741b1761b7e125

=== Operating System ===

Windows 6.2.9200.0 (64-bit)
Comment 2 Ankit Jain 2015-03-16 07:18:09 UTC
Fixed on mono master, as a result of the move to System.XML from referencesource.
Comment 3 Ankit Jain 2015-03-16 09:31:49 UTC
Note: this should be fixed as of ~ 50db47379083f823d0942870468df1fcda971f97 . This was tested with f482b9bd9b890cd99c3b93872a337b2b65f8f12b though.