I wrote a class in C++/CLI which inherits from System.Windows.Forms.UserControl. It works fine, but whenever I try to view some form which contains this control in designer view, it crashes with this error:

If I click on “Go to the Code”, I get sent to MainForm.Designer.cs, at the line where mConsole, the instance of my control, is added to the form. I am told it’s not declared, but that is done a few lines below. BeginInit is the first function called after new’ing mConsole, so Init was called before setting all properties. Everything looks right on this end.
The control’s dll is built with the /clr switch, and the Windows Forms project which uses it has the reference set. It builds and runs perfectly every time. The only problem is the design view. Every time I need to add some component, I have to edit the designer file manually, which is a real hassle.
Here’s some of my control’s code:
//Console.h
namespace MConsole {
public ref class MCConsole : public System::Windows::Forms::UserControl,
public System::ComponentModel::ISupportInitialize {
public:
MCConsole();
virtual ~MCConsole();
!MCConsole();
//Skipping custom properties and methods...
virtual void BeginInit();
virtual void EndInit();
protected:
virtual void OnPaint( System::Windows::Forms::PaintEventArgs ^ pe ) override;
};
//Console.cpp
#include "Console.h"
void MCConsole::Init(){
if( m_bInitialized )
return;
// Initialize native instance
m_pNativeInstance->Init( (HWND)this->Handle.ToPointer() );
m_bInitialized = true;
// Initialize timer
m_TimerTickHandler = gcnew System::EventHandler( this, &MCConsole::Render );
m_Timer.Tick += m_TimerTickHandler;
m_Timer.Interval = Math::Round<float, int>(1000.0f/FRAMES_PER_SECOND);
m_Timer.Start();
// Initialize event handlers
m_MouseWheelHandler = gcnew System::Windows::Forms::MouseEventHandler( this, &MCConsole::MouseWheelHandlerZoom );
this->MouseWheel += m_MouseWheelHandler;
m_ResizeHandler = gcnew System::EventHandler( this, &MCConsole::Resize );
this->SizeChanged += m_ResizeHandler;
m_MouseDownHandler = gcnew System::Windows::Forms::MouseEventHandler( this, &MCConsole::MouseDownHandler );
this->MouseDown += m_MouseDownHandler;
m_MouseLeaveHandler = gcnew System::EventHandler( this, &MCConsole::MouseLeaveHandler );
this->MouseLeave += m_MouseLeaveHandler;
m_MouseMoveHandler = gcnew System::Windows::Forms::MouseEventHandler( this, &MCConsole::MouseMoveHandler );
this->MouseMove += m_MouseMoveHandler;
m_MouseUpHandler = gcnew System::Windows::Forms::MouseEventHandler( this, &MCConsole::MouseUpHandler );
this->MouseUp += m_MouseUpHandler;
m_KeyPressHandler = gcnew System::Windows::Forms::KeyPressEventHandler( this, &MCConsole::KeyPressHandler );
this->KeyPress += m_KeyPressHandler;
m_DropHandler = gcnew System::Windows::Forms::DragEventHandler( this, &MCConsole::DropHandler );
this->DragDrop += m_DropHandler;
m_VisibleChangedHandler = gcnew System::EventHandler( this, &MCConsole::VisibleChangedHandler );
this->VisibleChanged += m_VisibleChangedHandler;
// Initialize layout wrapper
m_hRegionLayout = gcnew MCLayout( *m_pNativeInstance->getRegionLayout() );
m_bInitialized = true;
}
void MCConsole::BeginInit(){
Init();
}
void MCConsole::EndInit(){}
void MCConsole::OnPaint( System::Windows::Forms::PaintEventArgs ^ pe ) {
System::Windows::Forms::UserControl::OnPaint( pe );
if( m_bInitialized )
m_pNativeInstance->Refresh();
}
What I am missing or messing up? Or how can I debug the Designer crash?
UPDATE: I just tried starting another instance of Visual Studio and attaching to the process of the other VS. I configured the former to break on all kinds of exceptions, and I noticed that when I open the design view, I get ‘System.MissingMethodException’ with Additional information: Attempted to access a missing member. which eventually leads (hitting continue) to the message in the screenshot. If only I knew which method is missing…
It is finding an old copy of the DLL. Maybe the toolbox folder has an old copy, remove it from the toolbox and add it back. Maybe the GAC has an old copy, not very likely if it works okay at runtime.
If you can’t find it then run Fuslogvw.exe from the Visual Studio Command Prompt. Log all bindings so you can see where the CLR retrieved the assembly from.