6
votes

When dragging a control from the toolbox and dropping it in the Windows Forms designer, a message box appears with the message Object reference not set to an instance of an object.

After closing the message box, I can drop the control on the form without any other issue.

This happens on a new project as well. The error appears in both VS 2015 and 2017 (both community editions).

EDIT : This happens on any control, including custom ones. This started happening after I updated to the latest version of Windows 10 (17134.48).

7
Which control are you dropping? - LarsTech
@LarsTech I edited my question with further details - CristisS
What controls are currently on the form? Does this happen on a blank form? - LarsTech
@LarsTech This happens on both existing and new forms and in existing solution and new one. - CristisS
Well, something is borked. Try rebooting the computer one more time to see if it goes away. If it doesn't, then make sure your Visual Studios and .net libraries are up to date, too. - LarsTech

7 Answers

7
votes

Instead of dragging and dropping, Clicking on the control, then clicking on the form is the workaround working for me until they come out with a newer update.

This is new behavior as of Visual Studio 2017 Version 15.8.6 for me.

Hopefully this will help others that just kept dragging and dropping over and over like I was doing :-)

3
votes

Experiencing the same issue on Microsoft Visual Studio Community 2019 Version 16.5.0. I found that I was not able to drag and drop controls while VS was open on my high DPI external monitor, but if I moved VS to my native laptop monitor, I was able to drag and drop the controls.

2
votes

For Visual Studio 2017 I did not fix the problem, but I found a workaround:

  • went to C:\Users\user.name\AppData\Local\Microsoft\VisualStudio\15.0_e3603226
  • deleted all *.tbd, privateregistry.bin*, ApplicationPrivateSettings.xml files
  • deleted all files in ComponentModelCache folder
  • restarted Visual Studio as Administrator
  • it showed a message of updating the MEF files
  • drag and drop is NOT working. It keeps throwing the same error
  • BUT I can click on the item I want in the toolbox and then click on the designer without dragging and it works.

For Visual Studio 2015 I did not fix the problem, but I found a workaround:

  • went to C:\Users\user.name\AppData\Local\Microsoft\VisualStudio\14.0
  • deleted all *.tbd, *.lock, devenv.exe.config files
  • deleted all files in ComponentModelCache folder
  • restarted Visual Studio as Administrator
  • drag and drop is NOT working. It keeps throwing the same error
  • BUT I can click on the item I want in the toolbox and then click on the designer without dragging and it works.
2
votes

I have also seen the same problem repeated today in Visual Studio 2019 (Today is June 27 2019). I am trying out the VS 2017 solution from CristisS (above). I have verified that the 'workaround' still throws the exception, however, you can immediately draw the tool onto the form.

2
votes

I repeatedly run into the same issue. Seems to always be caused by running the Windows Forms designer on my secondary monitor. I don't know what causes it to misbehave, but moving Windows Forms Designer window back to my laptop screen always fixes the issue. Idk if it has something to do with scaling, or what, but it is a very repeatable issue that needs to be addressed.

0
votes

I found two solutions, to this problem that they worked for my WPF project in VS2015

solution 1) Click on the icon "enable/disable project code" in the bottom of windows design(the last icon near the percentual of zoom)-->Put Disable.

solution 2) Dx mouse button on your file .xaml and apply your modify in blend , selecting the "Open in Blend..." menu.

That's all

Daniel.

0
votes

Moving Visual Studio over from my hi res secondary monitor to my primary laptop monitor did fix the issue.

To use Visual Studio on my larger secondary monitor, I set my secondary monitor from 3840x2160 down to 2560x1440 and set scaling from 150% down to 100%

This lets me Drag and drop from the toolbox to the designer in Visual Studio 2019 (V16.11.3) without issue again.