Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 crashes when opening a form, containing an user control, in design mode

Following is my problem: I have a custom UserControl in my Windows Forms Project. I can design it in the designer just fine. But as soon as i want to edit the form which contains the control Visual Studio 2010 crashes.

As far as i could see the Constructor and the Load-Event of the control are executed on loading the form.

I tried using another instance of VS2010 to debug the designer, but could not find the location where the execption occurs.

At first my problem seemed to be, that for the Threading.Timer object, which i use for the initialisation of my Objects (i.e. Loading values from a Database and so on (on error try again later approach ;))), the Callback-Function was executed by the designer an therefore it attempted to access objects to which it had no access while in the design mode. The initialisation of the Threading.Timer Object is in the Load-Event. But even after i commented everything in the load event out (except a try catch block an a Debugger.Break() Call for having a breakpoint in the second instance VS2010 to debug the designer) Visual Studio keeps crashing as soon as I want to edit the form containing the control in design mode.

I tried some steps I found here without an answer to my problem: User control always crashes Visual Studio

So even if the designer has nothing to do when parsing the Load-Event or the Constructor. It still crashes.

Has someone an idea what I could do to prevent Visual Studio from crashing and displaying the user control properly in the forms designer?

The project containing the usercontrol also references some custom libraries and a library project. I don't know if the problem could have something to do with that.

like image 607
Nicholas Avatar asked Aug 10 '11 08:08

Nicholas


2 Answers

Solved somehow my own problem...

Somehow by trying to debug the designer mode i tricked myself.

Setting a Debugger.Break() in the Load-Event was a very bad idea while trying to open the form containing the user control in the designer mode, because if you are not debugging Visual Studio with another instance of Visual Studio then Debugger.Break() will stop the Application and therefore crashes the Visual Studio Instance.

In the end by Using the DesignerMode Property of the User Control I was able to prevent the designer from executing the initialisation of my threading.Timer Objects could solve the problem this way.

like image 128
Nicholas Avatar answered Sep 28 '22 08:09

Nicholas


I had this same issue(VS 2005), and the marked answer also didn't work for me. I was finally able to solve the issue by deleting the "obj" and "bin" folders in my solution and then rebuilding the project in release mode. I hope this helps anybody else who is having this issue.

like image 34
Gavin Perkins Avatar answered Sep 28 '22 08:09

Gavin Perkins