Bug 22124 - Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger doesn't handle hex strings
Summary: Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger doesn't handle h...
Status: RESOLVED UPSTREAM
Alias: None
Product: Compilers
Classification: Mono
Component: VisualBasic ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2014-08-14 16:38 UTC by Stephen E. Baker
Modified: 2018-05-22 12:21 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 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 UPSTREAM

Description Stephen E. Baker 2014-08-14 16:38:17 UTC
In Microsoft Visual basic you can convert a hex string starting with &H to an integer e.g. with the following code:

Module Module1

    Sub Main()
        System.Console.WriteLine(Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger("&H02B7"))
        Console.ReadLine()
    End Sub

End Module

The following Adrift bug suggests this isn't working in mono-basic 2.10: http://www.adrift.co/bug/18434

Conversion from string "&H02B7" to type 'Integer' is not valid.
at Microsoft.VisualBasic.CompilerServices.IntegerType.FromString (System.String.Value) [0x00000] in <filename unknown: 0
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger (System.String.Value) [0x00000] in <filename unknown: 0 


(I'm on Windows here where mono-basic doesn't seem to be available so I haven't run my test module in mono)
Comment 1 Stephen E. Baker 2014-08-14 19:51:12 UTC
I've compiled the above module in ArchLinux with vbnc2 and confirmed the issue:

Unhandled Exception:
System.InvalidCastException: Conversion from string "&H02B7" to type 'Integer' is not valid. ---> System.FormatException: Input string was not in the correct format
  at System.Int32.Parse (System.String s) [0x00000] in <filename unknown>:0 
  at Microsoft.VisualBasic.CompilerServices.IntegerType.FromString (System.String Value) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Microsoft.VisualBasic.CompilerServices.IntegerType.FromString (System.String Value) [0x00000] in <filename unknown>:0 
  at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger (System.String Value) [0x00000] in <filename unknown>:0 
  at Module1.Main () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidCastException: Conversion from string "&H02B7" to type 'Integer' is not valid. ---> System.FormatException: Input string was not in the correct format
  at System.Int32.Parse (System.String s) [0x00000] in <filename unknown>:0 
  at Microsoft.VisualBasic.CompilerServices.IntegerType.FromString (System.String Value) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at Microsoft.VisualBasic.CompilerServices.IntegerType.FromString (System.String Value) [0x00000] in <filename unknown>:0 
  at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger (System.String Value) [0x00000] in <filename unknown>:0 
  at Module1.Main () [0x00000] in <filename unknown>:0
Comment 2 Stephen E. Baker 2014-08-15 09:09:53 UTC
Additionally I noticed that the mono code is passing the string directly to System.Int32.Parse.

I tested System.Int32.Parse in Microsoft Visual Basic and it throws a FormatException on this string, so there has to be some parsing in between.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2018-05-22 12:21:05 UTC
Moved to: https://github.com/mono/mono-basic/issues/35