One or more errors encountered while loading the designer -- ConfigurationManager

Answered One or more errors encountered while loading the designer -- ConfigurationManager

  • Thursday, February 09, 2012 7:33 PM
     
     

    Hi to all.

    I'm working with VS 2005 and I have two  usercontrols;

    the first is ucTestAlfa and it contains only two textboxes.

    The second is ucTestBeta and is an inherited usercontrol.

    here the code of ucTestAlfa:

    ...

    using System.Configuration;

    ...

    public partial class ucTestAlfa : UserControl
    {
     String cnString = "";

     public ucTestAlfa()
     {
      InitializeComponent();

      
      cnString = ConfigurationManager.ConnectionStrings["XYCnString"].ConnectionString;
      
     }
    }

    And this the code of ucTestBeta (child of ucTestAlfa):

    public partial class ucTestBeta : ucTestAlfa
    {

     public ucTestBeta()
     {
      InitializeComponent();
     }
    }

    Well, when I'm working on ucTestAlfa in Design Mode, it's all right. But with ucTestBeta I'm getting errors while loading the designer.

    Why does the ConfigurationManager cause problems only with the ucTestBeta usercontrol?

    Here the workaround, but I'd like to understand the problem.

    http://social.msdn.microsoft.com/Forums/en/winformsdesigner/thread/4493eb02-7174-4940-9c1c-5a2c21e5e2f4

    Thanks.

All Replies

  • Monday, February 13, 2012 3:10 AM
    Moderator
     
     

    Hi Massimo XR1,

    Welcome to the MSDN Forum.

    First, we always create User/Custom controls in a separated Class Library project.

    Second, the Visual Studio will cache the first user control and the second user control can not show in design time in VS2005. If you can not open the second control in design form, please complie it first. Only the project complies successfully, the visual studio can cache it and load it in the design form.

    Best Regards


    Neddy Ren[MSFT]
    MSDN Community Support | Feedback to us

  • Wednesday, February 15, 2012 8:05 AM
     
     

    If I comment the line in ucTestAlfa:

    //cnString = ConfigurationManager.ConnectionStrings["XYCnString"].ConnectionString;

    and recompile successfully the project, then the design form will load without errors the ucTestBeta.

    Why does ConfigurationManager cause the crash?

  • Wednesday, February 15, 2012 8:30 AM
    Moderator
     
     

    If I comment the line in ucTestAlfa:

    //cnString = ConfigurationManager.ConnectionStrings["XYCnString"].ConnectionString;

    and recompile successfully the project, then the design form will load without errors the ucTestBeta.

    Why does ConfigurationManager cause the crash?

    So, would you please upload a small demon project for us. Maybe I can open it on my machine and help you to make sense of it.

    Best Regards


    Neddy Ren[MSFT]
    MSDN Community Support | Feedback to us

  • Wednesday, February 15, 2012 11:32 AM
     
     
    Excuse me, how can I upload the zipped project?
  • Thursday, February 16, 2012 1:06 AM
    Moderator
     
     
    Excuse me, how can I upload the zipped project?

    Yeap, you can upload the project to your skydrive which you can put it in the public folder and put your link here. We can download it from your skydrive public folder.

    Best Regards


    Neddy Ren[MSFT]
    MSDN Community Support | Feedback to us

  • Thursday, February 16, 2012 1:06 PM
     
     
  • Friday, February 17, 2012 1:59 AM
    Moderator
     
     Answered Has Code

    You can download the project from:

    https://skydrive.live.com/redir.aspx?cid=426fec1e4c51ec6c&resid=426FEC1E4C51EC6C!117&parid=426FEC1E4C51EC6C!119 

    Thanks.

    Yeap, I have got it.

    For the first, you haven't add a ConnectionString in your App.Config.

    The Second, you will need to add a Filed to achieve that and the Designer Form will works fine.

    Here is the fixed code:

    public partial class ucAlfa : UserControl
    {
        private string cnString;
    
        public string CnString
        {
            get 
            {
                return cnString = ConfigurationManager.ConnectionStrings["XYCnString"].ConnectionString.ToString();
            }
        }
    
       public ucAlfa()
       {
            InitializeComponent();
       }
    }

    Here is the screenshot:

    Best Regards


    Neddy Ren[MSFT]
    MSDN Community Support | Feedback to us

  • Friday, February 17, 2012 10:14 AM
     
     

    Thank you Neddy for your solution. I will use it.

    You wrote: "For the first, you haven't add a ConnectionString in your App.Config" .

    Yes, I know.

    I did it on purpose to demonstrate that the designer loads ucAlfa without problems, but it fails with ucBeta.

    I'd like to understand,  why ConfigurationManager is the problem (for ucBeta).

    Thanks.

  • Monday, February 20, 2012 6:29 AM
    Moderator
     
     

    Hi Massimo XR1,

    You should not interpret it as an error/bug and it is by design in Visual Studio. You can compile your project successfully. But such issue is not suggested.


    Neddy Ren[MSFT]
    MSDN Community Support | Feedback to us