Note that there are some explanatory texts on larger screens.

plurals
  1. PO"LNK2022: metadata operation failed" driving me insane
    text
    copied!<p>I have a big solution with lots of projects, using VS2008 SP1, and at least once a day I encounter the LNK2022 error. If I do a full rebuild of the solution it builds fine, but this is not fun.</p> <p>It happens when a dependent DLL is changed 'insignificantly' (i.e. without changing any methods or classes), and the referencing project is later built. It fails when merging the metadata - whatever that means.</p> <p>First thing to note is that the shared DLL is referenced with <code>#using</code> from multiple .CPP files.<br> Second thing is that if I delete the AssemblyInfo.cpp from the shared DLL then the problem goes away (but I'm <a href="https://stackoverflow.com/questions/807999/is-assemblyinfo-cpp-necessary">not sure if this is a sensible fix?</a>).</p> <p>I've narrowed it down as far as possible into the following <a href="http://www.2shared.com/file/5575794/7f03c4c4/xxx.html" rel="nofollow noreferrer">solution</a> containing 2 CLR Class Library projects (the <strong>xxx</strong> project depends on <strong>Shared</strong>):<br> <a href="http://i42.tinypic.com/jg2vds.png" rel="nofollow noreferrer" title="solution">alt text http://i42.tinypic.com/jg2vds.png</a></p> <p>Here are the contents of each file:</p> <h2>Shared.cpp:</h2> <pre><code>public ref class Shared { }; </code></pre> <h2>inc.h:</h2> <pre><code>#pragma once #using "Shared.dll" public ref class Common { private: Shared^ m_fred; }; </code></pre> <h2>xxx.cpp and xxx2.cpp:</h2> <pre><code>#include "inc.h" </code></pre> <p>To reproduce, first rebuild the solution. It will build OK.<br> Now save <em>Shared.cpp</em> and build the solution, it will build fine and show:</p> <pre><code>... 2&gt;------ Build started: Project: xxx, Configuration: Debug Win32 ------ 2&gt;Inspecting 'd:\xxx\xxx\Debug\Shared.dll' changes ... 2&gt;No significant changes found in 'd:\xxx\xxx\Debug\Shared.dll'. 2&gt;xxx - 0 error(s), 0 warning(s) ========== Build: 2 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== </code></pre> <p>Now save <em>xxx.cpp</em> and build the solution, it fails with the following message:</p> <pre><code>1&gt;------ Build started: Project: xxx, Configuration: Debug Win32 ------ 1&gt;Compiling... 1&gt;xxx.cpp 1&gt;Linking... 1&gt;xxx2.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: Common; fields: m_fred): (0x04000001). 1&gt;LINK : fatal error LNK1255: link failed because of metadata errors 1&gt;xxx - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ========== </code></pre> <p><strong>EDIT</strong>:<br> The differences between the IL for xxx.obj and xxx2.obj are as follows:</p> <p><strong><em>(for xxx.obj)</em></strong><br> // AssemblyRef #2 (23000002)<br> // -------------------------------------------------------<br> // Token: 0x23000002<br> // Public Key or Token:<br> // Name: Shared<br> // Version: 1.0.3412.16<b>606</b><br> // Major Version: 0x00000001<br> // Minor Version: 0x00000000<br> // Build Number: 0x00000d54<br> // Revision Number: 0x000040<b>de</b><br> // Locale: <br> // HashValue Blob: <b>1c bb 8f 13 7e ba 0a c7 26 c6 fc cb f9 ed 71 bf 5d ab b0 c0</b><br> // Flags: [none] (00000000)</p> <p><strong><em>(for xxx2.obj)</em></strong><br> // AssemblyRef #2 (23000002)<br> // -------------------------------------------------------<br> // Token: 0x23000002<br> // Public Key or Token:<br> // Name: Shared<br> // Version: 1.0.3412.16<b>585</b><br> // Major Version: 0x00000001<br> // Minor Version: 0x00000000<br> // Build Number: 0x00000d54<br> // Revision Number: 0x000040<b>c9</b><br> // Locale: <br> // HashValue Blob: <b>64 af d3 12 9d e3 f6 2b 59 ac ff e5 3b 38 f8 fc 6d f4 d8 b5</b><br> // Flags: [none] (00000000) </p> <p>This implies to me that xxx2.obj is still using the old version of Shared.dll, and that is conflicting with xxx.obj which is using the updated Shared.dll. So how can I workaround that then?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload