Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6000739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:44:13+00:00 2026-05-23T00:44:13+00:00

I want to have an abstract UserControl , BaseControl , that implements an interface

  • 0

I want to have an abstract UserControl, BaseControl, that implements an interface IBaseControl.
However, setting the class to abstract breaks VisualStudio designer (This is a known issue with Visual Studio (e.g., see this StackOverflow posting for more info), and as far as I know, there’s no change expected in the near future

So, to work around this, I make BaseControl not abstract, and its implementation of IBaseControl methods virtual. However, since these methods make no sense for a BaseControl (e.g., not all components have been added yet), I make them throw:

public class BaseControl : UserControl, IBaseControl
{
    /// <summary>
    /// This IBaseControl method is not abstract because 
    /// that breaks the Designer
    /// </summary>
    public virtual void LoadSettings()
    {
        throw new NotImplementedException("Implement in derived class.");
    }

    private void BaseControl_Load(object sender, EventArgs e)
    {
        // intention: derived methods automagically load their settings
        this.LoadSettings();
    }
}

In the derived control, I have the corresponding override:

public partial class DerivedControl : BaseControl
{
    public override void LoadSettings()
    {
        // load settings
    }
}

Despite this, when I try to open the control in the designer, I get an error indicating that the BaseControl.LoadSettings has thrown an exception.

Now, remember LoadSettings is called in the base class, so when the Designer loads the DerivedControl, it in turn calls the load method for the BaseControl, which throws.

Have you encountered a similar problem? How have you dealt with this? I’d like to have an elegant solution, if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:44:14+00:00Added an answer on May 23, 2026 at 12:44 am

    The reason that the exception is thrown is because, oddly enough, the designer doesn’t compile or instantiate the class your are designing at all! It only compiles and instantiates the base class of the control you are designing.

    Why this is the case becomes obvious when you realize that adding new subcontrols to the element would require further recompilation. Also, every event handler that you add modifies the class and again would require recompilation. Since event handlers will never be called in the designer anyway, this is all completely unnecessary. You design with a class that resembles your class but isn’t your class; it’s a work in progress.

    Since only the base class is instantiated, the base class cannot be abstract and it needs to be functional as is. If you throw exceptions, then the designer will see them. The only practical solution is to either:

    • Not throw exceptions from the base class, or
    • Conditionally not throw exceptions based on whether it is design-time or not.

    Either will work; use whichever you prefer or works best for your design. This is just the way the designer works and as you mention it is not likely to change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an abstract UserControl that I want to show a ToolTip on. This
I have one main interface and an abstract class implementing all derivable methods (that
I have a generic abstract UserControl class, SensorControl , which I want all my
I have an abstract base class and I want to declare a field or
I have an abstract class with a pure virtual function f() and i want
I have one abstract class -let's say myBase. And I want all the classes
I have a class with some abstract methods, but I want to be able
I want to have an abstract class Server with an abstract method called Initialize
I want to have an abstract class Employee, and 2 derived classes; Staff and
I understand that neither a abstract class nor an interface can contain a method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.