2

I have a project in Visual Studio 2010 (converted from 2008), and I have created a User control, like this:

namespace Common.Controls 
{
    public partial class Panel_BaseMap : UserControl 
    {
        public Panel_BaseMap()
        {
            //Some properties initialization here, just like = new X();
            InitializeComponent();
        }

        private void BaseMapPanel_Load(object sender, EventArgs e) {
            //Here, a new Thread is initialized and started.
        }
    }
}

I don't have any problem with this, it is opened in Design Mode without any problem. But I have created a new UserControl that extends to the first one, like this:

using Common.Controls;
namespace BC.controls 
{
    public partial class MapPanel : Panel_BaseMap 
    {
        public MapPanel()
        {
            InitializeComponent();
        }
    }
}

Well, in the very moment I try to open this new control on design mode, Visual Studio gets totally blocked, and I have to force it to close because it doesn't respond. I have tried many things, like for example:

public MapPanel()
{
    if (!this.DesignMode)
        InitializeComponent();
}

Still blocked. I have opened a second instance of Visual Studio, then on the first one "Debug --> Attach to process --> devenv" and I have put a breakpoint on the Load method and on both constructors on the second instance. The result: both instances totally blocked.

Can anyone help me, please?

Thank you very much in advance!

Roman
  • 1,691
  • 4
  • 18
  • 35
  • Use the DesignMode property to prevent code from executing in design mode. You most definitely don't want to start that thread for example. – Hans Passant Dec 15 '11 at 10:56
  • Like Hans said use designmode property.. but you need to check it in `BaseMapPanel_Load` not in `MapPanel()` because when you open MapPanel designer it will execute `Panel_BaseMap` Load event – Renatas M. Dec 15 '11 at 11:56
  • Ok I've found the problem. Some code was executed by the designer, and that code crashed the application. It was inside a try-catch, and inside the catch I logged the error with a method that tried to load an encripted file with this: Directory.GetFiles(Application.StartupPath, "*.xml"). The problem is that Application.StartupPath is not my application path, but "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Microsoft.Data.ConnectionUI.xml". So, when I tried to decrypt it, it throwed another exception, that was logged with the same method... so infinite loop! – Roman Dec 15 '11 at 12:49

1 Answers1

0

Ok I've found the problem.

Some code was executed by the designer, and that code crashed the application. It was inside a try-catch, and inside the catch I logged the error with a method that tried to load an encripted file with this: Directory.GetFiles(Application.StartupPath, "*.xml"). The problem is that Application.StartupPath is not my application path, but "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Microsoft.Data.ConnectionUI.xml". So, when I tried to decrypt it, it throwed another exception, that was logged with the same method... so infinite loop!

Roman
  • 1,691
  • 4
  • 18
  • 35