I have a windows form that contains a user control (each defined in separate assemblies). The control calls a factory method (defined in yet another assembly) to create a DataGridView CheckBox column:
datagridview.Columns.Add(DataGridViewUtilities.CreateCheckBoxColumn("Selected", false));
The code compiles and runs fine, and the control can be opened in Visual Studio 2017 Designer.
However, if I try to open the containing form in VS 2017 Designer, I get the following error:
Method not found: 'System.Windows.Forms.DataGridViewCheckBoxColumn DataGridViewUtilities.CreateCheckBoxColumn(System.String, Boolean, System.String, Boolean, System.Windows.Forms.DataGridViewAutoSizeColumnMode, System.Windows.Forms.DataGridViewColumnSortMode, Int32)'.
The callstack is:
at Control.SetupColumns(DataGridView grid)
at Control..ctor() in ...\Control.cs:line ##
Commenting out the line that calls CreateCheckBoxColumn() allows the containing form to be opened properly in VS Designer.
CreateCheckBoxColumn() is declared as:
static public DataGridViewCheckBoxColumn CreateCheckBoxColumn(string dataPropertyName, bool readOnly = true, string columnName = null, bool threeState = false, DataGridViewAutoSizeColumnMode autosizeMode = DataGridViewAutoSizeColumnMode.None, DataGridViewColumnSortMode sortMode = DataGridViewColumnSortMode.Automatic, int width = 35)
{
...
}
A weird thing is that the control calls a similar static method defined in the same class as CreateCheckBoxColumn(), and that other method is not interfering with opening the form.
I tried rebuilding, manually deleting the contents obj & bin directories for all 3 projects, as well as the contents of AppData\Local\Microsoft\VisualStudio\15.0_6d397e1a\ProjectAssemblies, closing all open documents in VS 2017, closing the solution, and restarting Visual Studio, and it made no difference.
I tried to add a new (test) form to the same project (the project containing the form that couldn't be opened in Visual Designer), and added the offending control to it by dragging it from the toolbox. However when drop the control an error dialog comes up saying
Failed to create component 'Control'.
The error message follows:
'System.MissingMethodException: Method not found CreateCheckBoxColumn(...)
What's wrong, and how do I fix this without having to comment out code to open the control in designer?