Windows 10 1803 x64 Build 17134.165, Visual Studio 2017 15.7.5 c#
I have a custom combo box on a form. If I build the solution targeting Any CPU then there is no problem, but if I change the target to x64 then I get this error in the designer, and the combo box is removed from the toolbox. The code in designer.cs is intact and the program still runs fine.
Could not find type 'TestCustomComboBox.ComboBoxCustom'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU.
If I revert to Any CPU then the error goes away and the combo box is back in the toolbox. My computer is x64.
Complete test program:
using System.Drawing;
using System.Windows.Forms;
namespace TestCustomComboBox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
/// <summary>
/// Custom combobox with colour coding
/// </summary>
public class ComboBoxCustom : ComboBox
{
public ComboBoxCustom()
{
this.DrawMode = DrawMode.OwnerDrawFixed;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
e.DrawBackground();
var item = (ComboBoxItem)Items[e.Index];
Brush brush = new SolidBrush(item.ForeColor);
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{ brush = Brushes.Yellow; }
e.Graphics.DrawString(item.Text, this.Font, brush, e.Bounds.X, e.Bounds.Y);
}
}
public class ComboBoxItem
{
public ComboBoxItem() { }
public ComboBoxItem(string pText, object pValue)
{
text = pText; val = pValue;
}
public ComboBoxItem(string pText, object pValue, Color pColor)
{
text = pText; val = pValue; foreColor = pColor;
}
string text = "";
public string Text
{
get { return text; }
set { text = value; }
}
object val;
public object Value
{
get { return val; }
set { val = value; }
}
Color foreColor = Color.Black;
public Color ForeColor
{
get { return foreColor; }
set { foreColor = value; }
}
public override string ToString()
{
return text;
}
}
public class ComboObject
{
public string DisplayMembers;
public int ValueMembers;
public int argb;
public ComboObject(string theDisplayMembers, int theValueMembers, int theArgb)
{
DisplayMembers = theDisplayMembers;
ValueMembers = theValueMembers;
argb = theArgb;
}
public override string ToString()
{
return DisplayMembers;
}
}
}