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 开发者_如何学Pythonsee 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.
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.
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.
To follow up on womb's post, I found the following code to help out and block VS from crashing and reading the onLoad function.
I cannot reply and did not want to add a new comment. You can use the following in the Load method and stop VS from reading it and crashing. This was taken from this article
bool isDesignMode = (System.Diagnostics.Process.GetCurrentProcess().ProcessName.IndexOf("devenv") != -1);
if (isDesignMode)
return;
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.
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
}
To me helps changing Target Framework from ".Net Framework 4 Client Profile" to ".Net Framework 4" in project settings.
Try to comment out parts or even the complete constructor of the control and see if it shows up. Maybe it is another initialization that fails, too.
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!
I've had some similar problems when creating my own user controls in Visual Studio, but have been able to get the user controls to display properly by following these steps:
- Build or rebuild the project / solution
- Close Visual Studio and reopen it
These are pretty basic things that I bet you've already tried. Just throwing it out there.
Recently I had annoying error after creating user control and attached it to form via designer, visual studio 2010 would always crash whenever design mode of same form where user control were attached.
After creating so many times and lot of experimentation i solved my problem by:
1 - Adding new class.cs file to project 2 - Moving all extra-supporting classes that I had added to user control itself 3 - I think this is more important: moving all custom delegates that wires events on User_Control to newly added file. 4 - Deleted User_Control.Load event.
I hope this may help someone.
Cheers
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.
I had problems with the IDE crashing/restaring VS.
This was specific to my using a Customer Designer (inherited from ParentControlDesigner) that I used to apply EnableDesignMode (and some smart tag work).
My problem VS crashing whilst adding my user control to a form (It's a big program and I have lots of Custom and User Controls) occured only when the EnableDesign was used - commen ting it out ceased the problem. This turned out to be a simple property in the User control setting a property of an underlying Custom Control (refrerring to itself as a reference for the child Custom Control so not a recursive issue). I don't know why this made a difference but it did or at least it's now working when I removed it.
The other problem I had, when removing the User control (unloading) from a form within the IDE, again was only due to the Designer inclusion. This was resolved by adding a specific dispose in the user user control dispose event that disposed the item(s) mentioned in the EnableDesign.
Debugging via a second VS instance didn't help as much as it could've (it just said Stackoverflow before going wrong and not related to the next logical line) but it did offer a clue of the general area of concern. This issue cost me days hence my report here in case it helps someone.
Needless to say my program continued to always work correctly when actually running and so it was purely a designer/VS IDE issue.
精彩评论