Designer Support when Control has abstract base class

We have a set of user Controls that must derive from an abstract base class BaseControl. BaseControl itself is derived from UserControl. Is there a way enable designing and modifying those user Controls in the VS 2005 Forms designer AND have them derived from an abstract base class Currently we get this Excpetion when trying to open those user controls in the designer:

The designer must create an instance of type XYZ.Controls.BaseControl' but it cannot because the type is declared as abstract.

at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)





Answer this question

Designer Support when Control has abstract base class

  • dotnetsr

    you can try emailing brian pepin if it is still reproducible or comment on the blog post. i haven't tried it though yet. good luck!


  • SingWei

    I have found out that when the designer stops working and displays that "can not design because of abstract base class" it is not necessary to delete any files. All you need to do is to close and reopen visual studio.

  • gsell

    I tried the approach described there in Visual studio 2005 for both a usercontrol and a form and it works almost perfect. It's very easy to do and not tedious at all.

    Except:

    From time to time (I have't found out when exactly this happens) the designer still says "can't design because of abstract base class" but when I close VS, delete both the "obj" and the "bin" folders, reopen VS and then rebuild the solution it works again. For some reason, that I haven't found yet, the VS 2005 desinger stops using the TypeDescriptionProvider and tries to create an instance of the (abstract) baseclass directly. To me this looks like a Bug in VS. The behavior is very hard to reprocude. It just happens form time to time.

    Any input is welcome.



  • farsh

    Hi,

    Further to the discussion on the above URL,

    suppose if we have more than one concrete class, then we can not use

    [ConcreteClass(typeof(<concrete class name>))] attribute. So, this will not work for some thing like a factory pattern.

    Rgds

    Rajani Kanth


  • FritzDeVries

    here is the description how you can have designer support for abstract base classes:

    http://www.urbanpotato.net/default.aspx/document/2001



  • jcavazos

    I have seen a previous blog post of Brian Pepin on this issue (but with forms) and i have even blogged about it months ago. I don't know if the workaround is still possible with the release version of vs 2005.


  • Malebolgia

    bitbonk wrote:

    here is the description how you can have designer support for abstract base classes:

    http://www.urbanpotato.net/default.aspx/document/2001


    am glad you found it. are there any issues with it and the release version of vs2005 it's pretty tedious imo coz i can settle with a non-abstract base control


  • msorens

    It is not possible what you want...

    The Derived class is being designed. While it is being designed, the designer needs

    a "placeholder" or stand in for the class being designed.

    It cannot use the derived class, because:

    it may not be compiled yet

    it may have errors and fail to compile

    even if it does compile, the class would have to be loaded repeatedly, once after

    each compile, and there would be dll loading problems internally in VS

    So the simplest solution is to use the base class as the placeholder.

    This means your base class cannot be abstract.

    a work around is: implement the members that would be abstract

    and have them throw exceptions.

    Remco


  • Designer Support when Control has abstract base class