Null reference when callling InitializeComponent

Peter Toye 191 Reputation points
2021-05-16T15:44:26.037+00:00

I have just converted a VB Windows Forms project from .NET 4.7 to .NET 5. When I try to run it I get a Null Reference exception on the call to InitializeComponent at the head of the call of New() to the main form - see the screen shot. This is odd because there's nothing to reference apart from Me, which has surely been instantiated by the time this call is made - certainly hovering the cursor over local field names gives a value.
96810-nullref.png

It's possible that I've left something out of the project file when editing it, but I can't see what.

Developer technologies VB
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2021-05-16T17:49:28.083+00:00

    Click “View Details”, investigate and show the details and try determining the problematic line of InitializeComponent.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-05-16T17:23:17.9+00:00

    For a .NET 5 form, InitializeComponent is in the form designer file not in user code (when double clicking on the form)

    96974-figure1.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.