Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger doesn't handle hex strings #35

Open
rolfbjarne opened this issue May 22, 2018 · 1 comment

Comments

@rolfbjarne
Copy link
Member

rolfbjarne commented May 22, 2018

Submitted by a community member on 2014-08-14 16:38 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)


Xamarin Bugzilla comment 1 by a community member on 2014-08-14 19:51 UTC

I've compiled the above module in ArchLinux with vbnc2 and confirmed the issue:

Unhandled Exception:
System.InvalidCastException: Conversion from string "&amp;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 "&amp;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

Xamarin Bugzilla comment 2 by a community member on 2014-08-15 09:09 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.


Reference: https://bugzilla.xamarin.com/show_bug.cgi?id=22124

@TheCycoONE
Copy link

I created this ticket on Bugzilla.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants