none
LNK2022: Metadata Operation Failed

    Question

  • Hi,

    We are facing some linker errors while compiling C++ code in C++/CLI with /clr compiler option enabled.

    We are getting LNK2022: Metadata Operation Failed -  : Inconsistent layout information in duplicated types (<Class Name>).

    Is it really related to duplicating types? In some places our Code consists of two class declarations which will fall under macro.

    If macro is enabled first declaration will be considered by the compiler or else second one need to get considered

    For example

    #ifndef __MARCO_FOR_MYCODE__
    class A()
    {
             public:
                void myCode();
    }
    #else
    class A()
    {
             public:
                void myFunc();
                void retValue();
    }
    #endif

    How C++/CLI compiler will convert into metadata? How we can resolve this issue?

    Please suggest me if you have any idea
    Monday, March 15, 2010 5:27 AM

Answers

  • Hi _Superman_,

    It is possible to have multiple definations with in marco condition. Under normal VC++ compiler it will work. Thanks for your reply. My problem got solved. Due to some improper inclusion of header file (which contains all the macro's) i am getting that error. Now i figured the problem and resolved it.

    Thank you very much.

    Regards,
    Krishna K Kandula
    • Marked as answer by Nancy Shao Tuesday, March 16, 2010 9:30 AM
    Monday, March 15, 2010 10:03 AM

All replies

  • Is there a chance that one CPP file compiles one version of class A and another compiles the other version of class A?
    If this happens, the linker will not be able to merge the meta-data of the 2 classes and will result in this error.

    «_Superman_»
    Microsoft MVP (Visual C++)
    Monday, March 15, 2010 9:22 AM
  • Hi _Superman_,

    It is possible to have multiple definations with in marco condition. Under normal VC++ compiler it will work. Thanks for your reply. My problem got solved. Due to some improper inclusion of header file (which contains all the macro's) i am getting that error. Now i figured the problem and resolved it.

    Thank you very much.

    Regards,
    Krishna K Kandula
    • Marked as answer by Nancy Shao Tuesday, March 16, 2010 9:30 AM
    Monday, March 15, 2010 10:03 AM