Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Studio 2005 (designer) is crashing

Status
Not open for further replies.

MKuiper

Programmer
Jan 29, 2002
364
NL
I'm afraid this question is more about VS2005 than it is about C#, but I can't find an other more appropriate forum on this site to post this.

I have made a derived class of UserControl (C#, let's call it MyUserControl). There are no changes made to it in the designer, because every control on it is generated dynamically at run time. So the thing is quite complex, but it runs fine.
When i open it using the designer, all i see is a gray square. Also this is fine.
Next thing i need is deriving classes of it containing controls put on it using the designer. And this is where it goes wrong. When I add (from Solution Explorer) a derived UserControl to the project and let it inherit from MyUserControl, Visual Studio exits. No error message, no error log, and no more Visual Studio.
I have done some logging in the constructor of MyUserControl, and the constructor is completely executed without error. Also i have commented out all the eventhandlers which might perhaps be executed when the derived class is loaded in the designer. No help.
Because MyUserControl contains a lot of code, the process of commenting out everything until the cause of this behaviour is found, might take a lot of time.
So if somebody knows a common reason why Visual Studio Desiger exits, please post it here.

Thanks in advance


Marcel
 
Did you modify anything in the "InitializeComponent()" section?

Visual Studio has taken a dump on me when I did that a looong time ago.
 
There is no InitializeComponent method in MyUserControl, because MyUserControl has not been made by the designer. If there would be an InitializeComponent method, it would be called from the constructor and the constructor is executed normally.
In fact, I already changed the constructor like this:

MyUserControl ( )
{
MessageBox.Show ( "Start MyUserControl contructor");
//
// existing constructor code
//
MessageBox.Show ( "End MyUserControl constructor");
}

Both messages do appear before VS terminates.


Marcel
 
JurkMonkey,

I'm not sure about the solution. What I have done is commenting everything out of MyUserControl and putting it back in small steps to find out what was responsible.

I have found this piece of code:

Code:
public class MyUserControlProperties
{
    // here a lot of other public variables
    public MyUserControl myUserControl;
}

public class MyUserControl : UserControl
{
    private MyUserControlProperties myUserControlProperties
            = new MyUserControlProperties();
    // a lot of other private variables

    MyUserControl()
    {
        myUserControlProperties.myUserControl = this;
        // other initialization
    }

    public MyUserControlProperties MyProperties
    {
        get { return myUserControlProperties; }
    }
}

And changing the access modifier
public MyUserControlProperties MyProperties
to
internal MyUserControlProperties MyProperties

solved the problem (and yes, internal can be used in my situation instead of public).
But it must be a combination of the issue above and something else in the original MyUserControl and/or MyUserControlProperties class, because I have tried the simple situation described above, that does not let VS crash.


Marcel
 
Found it after all.

Instead of

public MyUserControlProperties MyProperties
{
get { return myUserControlProperties; }
}

i had accidentally written

public MyUserControlProperties MyProperties
{
get { return myProperties; }
}

causing an infinite recursion and a stack overflow.
I think i'm going to make an appointment with an eye-doctor, I read that piece of code a 1000 times, and found the error only the 1001st time.
I didn't even copy the error right in the example.
When you change the example, it will generate the same error.
Being deeply ashamed,


Marcel
 
Being deeply ashamed,

An so you should. But it could have been worse, you could have seen it the 201st time and dismissed it as not relevant and then ended up in a recursive loop.

Christiaan Baes
Belgium

"My new site" - Me
 
It's like discovering your belly button at the age of 25 : where.. did that come from?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top