User control always crashes Visual Studio

2019-02-08 16:59发布

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.

11条回答
再贱就再见
2楼-- · 2019-02-08 17:08

Hangs like these are usually associated with networking. A database perhaps. You have to watch out for code that runs inside the UserControl at design time. Not just the constructor, also the Load event, timers, OnHandleCreated, OnResize, etcetera. The way to avoid running that code is by testing the DesignMode property, don't do anything dangerous when it is true.

Your ultimate fallback is to debug the code at design time with another instance of Visual Studio.

查看更多
男人必须洒脱
3楼-- · 2019-02-08 17:13

After all that you have done, I would also try to load the user control in a brand new project, and see if it loads correctly; and if it does, then you can "decide where to insert some new components"... just thinking out loud!

查看更多
一夜七次
4楼-- · 2019-02-08 17:17

To me helps changing Target Framework from ".Net Framework 4 Client Profile" to ".Net Framework 4" in project settings.

查看更多
我只想做你的唯一
5楼-- · 2019-02-08 17:19

I had the same problem. In my case, the problem was (I think) that I was initializing a member array in the declaration instead of in the constructor. The error was that the the VisualStudio project for my application immediately crashed when I tried to use the custom control from my lib that had the "bad" declaration.

It was frustrating because my custom component lib compiled with no errors.

Brooke

code that crashed:

class MyCustomObject: UserControl
{
  private List<int> myList = new <int>List();
   public MyCustomObject(){
      InitializeComponent();
     }

// other code here
} 

solution

class MyCustomObject: UserControl
{
   private List<int> myList;
   public MyCustomObject(){
        InitializeComponent();
        myList= = new <int>List();
     }

// other code here
} 
查看更多
Emotional °昔
6楼-- · 2019-02-08 17:19

I have come across this problem as well. I Have one project(ProjA) that contains user controls and another project(ProjB) that references those user controls. I found that every time I attempt to add a particular user control the vb.net Environment shuts down and reloads my solution. However, if I comment out the code that's contained within my controls LOAD event

 Private Sub SampleDisplayBox_Load(sender As Object, e As EventArgs) Handles Me.Load
        'AddHandler Sample.Sample_Reloaded, AddressOf reload
        'AddHandler Sample.Sample_Cleared, AddressOf SampleCleared
        'AddHandler My.Settings.SettingsSaving, AddressOf UpdateColors
        'UpdateColors()
        'reload()

    End Sub

and then rebuild my solution, I run into no problems when adding this control to a form. It's very strange that this problem occurs in only one control when I have 7 other controls in the same project that all function in the same manner with no errors.

Personally, I think VB.NET hates me.

查看更多
趁早两清
7楼-- · 2019-02-08 17:21

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.

查看更多
登录 后发表回答