0

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;
        }
    }
}
Gerry
  • 129
  • 2
  • 13
  • 1
    AFAIK the Visual Studio and/or the VS Designer runs as 32bit process, so when you compile your control for 64bit only then the designer will not be able to load it. So IIRC you'll have to compile your control for "AnyCPU" or "x86", at least as long as you're going to use the designer during development... (Maybe take a look at the following related / similar question: https://stackoverflow.com/questions/5378919/visual-studio-designer-in-x64-doesnt-work) – bassfader Jul 18 '18 at 09:55
  • Thanks, it makes some sense now. I do have a catch 22 issue though. I call an assembly that will only run when compiled as x64. It does work but with warnings. I guess it is design under Any CPU and compile for x64 to deploy. BTW, how would you mark a comment as Best Answer? – Gerry Jul 18 '18 at 10:24

0 Answers0