Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User control always crashes Visual Studio

I'm trying to open a user control in one of our projects. It was created, I believe, in VS 2003, and the project has been converted to VS2008. I can view the code fine, but when I try to load the designer view, VS stops responding and I have to close it with the task manager. I have tried leaving it running for several minutes, but it does not do anything. I ran "devenv /log" but didn't see anything unusual in the log. I can't find a specific error message anywhere. Any idea what the problem might be? Is there a lightweight editing mode I might be able to use or something?

The reason I need to have a look at the visual representation of this control is to decide where to insert some new components.

I've tried googling it and searching SO, but either I don't know what to search or there is nothing out there about this. Any help is appreciated.

(The strangest thing is that the user control seems to load fine in another project which references, but VS crashes as soon as I even so much as click on it in that project.)

EDIT

The user control is a wrapper of a 3rd party HTML editor...so not exactly something which accesses a database.

I just tried putting the control on a new project and it crashed as soon as I dragged it onto the form.

like image 477
NickAldwin Avatar asked Apr 18 '10 20:04

NickAldwin


People also ask

Why does my Visual Studio keeps crashing?

If you experience crashes of Visual Studio, typically when working with a very large solution, your IDE might be out of virtual memory. Typical indicators of the problem include a "one or more errors occurred" message, "the process appears to be deadlocked" message, and OutOfMemory exception in a crash dump.

How do I stop Visual Studio from crashing?

Please open CMD and go to C:\Program Files (x86)\Microsoft Visual Studio\2019\version name\Common7\IDE folder, run the command: devenv /safemode to run your Visual Studio in safe mode. Then, create a new project and check if the installed extensions lead to the problem or not.


2 Answers

I solved my crashing designer using techniques described here:

Good Way to Debug Visual Studio Designer Errors

I've been able to debug some control designer issues by running a second instance of VS, then from your first VS instance do a "Debug -> Attach to Process" and pick "devenv".

AND

It seems that the Load() method of UserControls somehow gets parsed by the designer. Putting initialisations and other suspicious code in a if - loop - checking for IsDesignMode keeps the designer from reading code that will crash it ....

--update: looking back now, all most things solved when I overthought / refactored the application design.

like image 193
womd Avatar answered Oct 16 '22 09:10

womd


Your user control may have a property written like this:

private int myPropName; // note the lowercase m
public int MyPropName { get { return MyPropName; } } // the property is returned
                                                     // instead of the variable

Note that the value returned by get is the property itself. This crashes VStudio 2008 when trying to see the properties of the control, which also happens when adding the control (by drag'n drop or else) to a Form.

As pointed out by NickAldwin, this does not generate compiler warning or error.

like image 28
Gabriel Avatar answered Oct 16 '22 10:10

Gabriel