Winforms User Control MissingMethodException

2019-08-14 20:55发布

So essentially, I have a custom user control called ExcelDisplay. I try to drag it over in visual studio from the toolbox into my webform in the same project and I get a missing method exception. At one time the constructor was parameterized, but I changed it after deciding it was a bad design idea.

It looks like it is saying the constructor is missing, but its obviously there.

My winform to house the control is empty with the exception of the autogenerated code visual studio puts there.

The code for my ExcelDisplay's constructor looks like this.

    namespace STS_Console.UserControls
    {
        public partial class ExcelDisplay : UserControl
        {

            public ExcelDisplay()
            {
                InitializeComponent();

                DataDisplay.Columns[0].HeaderText = "Data";
                //debug
                string x = DataDisplay.Columns[0].GetType().ToString();
                x.ToString();
            }

The error message is this. error message

So that error occurs when do I drag and drop in the designer like this  Drag and drop

Anyway so that is my problem. I am not sure what is causing it or how to fix it. I would be glad to post additional code upon request.

2条回答
迷人小祖宗
2楼-- · 2019-08-14 21:20

Rebuild Solution fixed it for me, although if your making regular changes to your user control, you should put them into a separate project.

My particular problem, was a user control, within a user control.

查看更多
Bombasti
3楼-- · 2019-08-14 21:33

You should put your user controls in a class library of their own. For the designer to work, it needs a compiled version of your user control. If you cannot compile your user control before you compile your form, you will get into all kinds of trouble.

查看更多
登录 后发表回答