Visual Studio 2017 and 2019, using VB.NET, will not load Form with HexNumericUpDown, modified NumericUpDown, control in it when CompileTarget CPU is x64.

Paul Marshall 1 Reputation point
2022-05-19T05:52:40.567+00:00

I converted some C# code (from answer to "numericUpDown Hexadecimal bug") to VB which is listed below. Visual Studio 2017 using VB.NET, will not load the Form with a HexNumericUpDown, modified NumericUpDown, control in it when Compile Target CPU is "x64". I use this control to display Uint64 values in hex.

I add the following code to my project "Expermental" and compiled it with Compile Target CPU as "Any". Then add HexNumericUpDown to Form1 from the toolbox. Compiled it again use Compile Target of "x64". Then when I try to edit Form1.vb [Design] I get the following error messages:

To prevent possible data loss before loading the designer, the following errors must be resolved:

  1. "Could not find type 'Expermental.HexNumericUpDown'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU."
  2. "The variable 'HexNumericUpDown1' is either undeclared or was never assigned."

The control seems to work ok when I run it, but I can't edit the form unless set the Compile Target CPU back to "Any" and compile it again. This is driving me nuts. I also tried Visual Studio 2019 with the same results.

Is there a way to fix this?

Imports System.ComponentModel
Imports System.Windows.Forms

Friend Class HexNumericUpDown

Inherits NumericUpDown

Public Sub New()
    MyBase.Hexadecimal = True
    MyBase.Minimum = 0
    MyBase.Maximum = UInt64.MaxValue
End Sub

<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Shadows Property Maximum() As Decimal
    ' Doesn't serialize properly 
    Get
        Return MyBase.Maximum
    End Get
    Set(ByVal value As Decimal)
        MyBase.Maximum = value
    End Set
End Property

Protected Overrides Sub UpdateEditText()
    If MyBase.UserEdit Then
        HexParseEditText()
    End If
    If Not String.IsNullOrEmpty(MyBase.Text) Then
        MyBase.ChangingText = True
        MyBase.Text = String.Format("{0:X}", CULng(Math.Truncate(MyBase.Value)))
    End If
End Sub

Protected Overrides Sub ValidateEditText()
    HexParseEditText()
    UpdateEditText()
End Sub

Private Sub HexParseEditText()
    Try
        If Not String.IsNullOrEmpty(MyBase.Text) Then
            Me.Value = Convert.ToUInt64(MyBase.Text, 16)
        End If
    Catch
    Finally
        MyBase.UserEdit = False
    End Try
End Sub

End Class

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,836 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,580 questions
{count} votes