Search code examples
c#formsdesignermissingmethodexception

MissingMethodException when opening a form in the designer; runtime works fine


Let's say I have a projoct A with a class A that has this property:

    public bool IsConnected
    {
        get { return m_isConnected; }
        private set { m_isConnected = value; }
    }

In the same solution, I have a project B that references project A and has a user control called Login. This control has this attribute:

    private A m_A = null;

and in the contructor of Login I do this call:

if (m_A != null && m_A.IsConnected) { ... }

In the same project, the main form has on it a user control A that was added with the form designer. The program runs fine and this property is correctly read.

However, when opening the main form in the Designer I get this execption: MissingMethodException: 'Boolean A.get_IsConnected()'

Commenting out m_A.IsConnected let's me use the designer, but this is getting pretty annoying. And sometimes it seems like it randomly just works.

Any ideas?


Solution

  • I've been told in the past that this.DesignMode isn't always perfectly reliable. The other option you can use is preprocessor directives:

    #if DESIGN
    return;
    #else
    if (m_A != null && m_A.IsConnected) { /* etc. */ }
    #endif
    

    Then add a conditional compilation symbol named DESIGN and you should be golden.