Converting to Hex returns strange error

191 views Asked by At

The following simple expression raises ArgumentOutOfRange on my end:

100.ToString("X4")

I have tried replacing 100 with other constant values and integer variables, and have got the same result. I have changed X4 to X6 and simply X as well, again getting the same exception. The error message is:

Enum value was out of legal range.

Has anyone seen this before, or am I missing something really simple?

EDIT

Here's a complete small program that reproduces it on my end (A Console Win application, add reference to System.Drawing):

Imports System.drawing

Module Module1
  Sub Main()
    Dim x As New ColorRange()
    Console.Write(x.ToString())
    Console.Read()
  End Sub

  Class ColorRange
    Public Overrides Function ToString() As String
      Return 100.ToString("X") & " - " & 100.ToString("X")
    End Function
  End Class
End Module

EDIT 2

It looks like the error (bug?) is in the debugger. The value prints fine at runtime. Thanks to Jon. This is VS2010 Ultimate SP1 + Win 7 (64-bit) if anyone is interested.

0

There are 0 answers