locked
Missing method exception

    Question

  • Hi, please explain me why I am getting an MissingMethodException in my C# code when I call this C++/CX method :

    public ref class Factory abstract
    {
    
    public :
    
    	static void Init( ) { /*Empty*/ } // <- MissingMethodException.
    };

    Sunday, July 15, 2012 9:04 AM

Answers

  • Hi,

    Does replacing "abstract" with "sealed" / adding "sealed" resolve the issue?

    -Sagar

    • Marked as answer by t-n-x Tuesday, July 17, 2012 9:00 AM
    Monday, July 16, 2012 2:35 PM
    Moderator
  • Hi t-n-x,

    I Have created a C++/CX application with this same method, and a C# Metro app referencing the C++ one to test this issue.

    If we declare the Factory class like this: , we are not able to call it from the C# side.

    While, If abstract was changed to sealed, the complication is correct. 

    So please use sealed instead in this case.

    From this link: http://msdn.microsoft.com/en-us/library/b0z6b513(v=vs.110).aspx, we can know that: The abstract keyword indicates that a type member function can be defined only in a derived type. Therefore, you got the MissingMethodException when using it with the base class.

    Best regards,


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Helen Zhao Tuesday, July 17, 2012 8:32 AM
    • Marked as answer by t-n-x Tuesday, July 17, 2012 8:59 AM
    Tuesday, July 17, 2012 8:25 AM

All replies

  • Hi,

    Does replacing "abstract" with "sealed" / adding "sealed" resolve the issue?

    -Sagar

    • Marked as answer by t-n-x Tuesday, July 17, 2012 9:00 AM
    Monday, July 16, 2012 2:35 PM
    Moderator
  • Thanks, yes I can only call the static method from a sealed class but not from an abstract class :/

    Is it a bug or a known limitation ?

    Tuesday, July 17, 2012 8:11 AM
  • Hi t-n-x,

    I Have created a C++/CX application with this same method, and a C# Metro app referencing the C++ one to test this issue.

    If we declare the Factory class like this: , we are not able to call it from the C# side.

    While, If abstract was changed to sealed, the complication is correct. 

    So please use sealed instead in this case.

    From this link: http://msdn.microsoft.com/en-us/library/b0z6b513(v=vs.110).aspx, we can know that: The abstract keyword indicates that a type member function can be defined only in a derived type. Therefore, you got the MissingMethodException when using it with the base class.

    Best regards,


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Helen Zhao Tuesday, July 17, 2012 8:32 AM
    • Marked as answer by t-n-x Tuesday, July 17, 2012 8:59 AM
    Tuesday, July 17, 2012 8:25 AM
  • Thanks for the explanation : )
    Tuesday, July 17, 2012 8:59 AM