Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constructor on type 'Track_Attack.TAGeneric' not found. C# Winforms

I'm getting a warning message in Visual Studio 2010 (the one in the title)

Basically I've made a generic form which has a bunch of variables, virtual functions.

It takes a class I made as a parameter and assigns it to a local variable (which is then put as a propety using getters and setters)

I then made another form which inherits from this form. All is well, it runs, but when I attempt to look at the designer of it, I get that error message.

    public TAGeneric(TAManager iManager)
    {
        ControlHelper.SuspendDrawing(this);

        mManager = iManager;

        SetStyle(ControlStyles.OptimizedDoubleBuffer |
            ControlStyles.UserPaint |
            ControlStyles.AllPaintingInWmPaint, true);

        InitializeComponent();
        SetupCommandBar();
        ControlHelper.ResumeDrawing(this);
    }

Thats the parent.

    public TAAddInterval(TAManager iManager) : base(iManager)
    {
        InitializeComponent();
    }

This is a child. Forget the fact I'm using a "manager" when it is frowned upon. Anyone shed some light on the problem? Literally works fine to run, but when it comes to trying to edit the graphical side in designer, It won't load it.

Thanks for the help.

like image 657
ICTech Avatar asked Dec 27 '22 17:12

ICTech


2 Answers

I suspect you need to provide a parameterless constructor for the designer to use:

public TAAddInterval(TAManager iManager) : base(iManager)
{
    InitializeComponent();
}

[Obsolete("This constructor only exists for the benefit of the designer...")]
public TAAddInterval() : this(null)
{
}

If you have some sort of fake TAManager you could provide instead, that might avoid NullReferenceException being thrown if the designer happens to hit some code which uses the manager.

like image 73
Jon Skeet Avatar answered Feb 13 '23 02:02

Jon Skeet


You likely just need a parameterless constructor and the designer will work fine.

like image 20
Mike Perrenoud Avatar answered Feb 13 '23 04:02

Mike Perrenoud