error LNK2022: metadata operation failed (801311D6) : Differing number of methods in duplicated types

本文主要是记录一个C++编译错误的解决方案,具体错误请看本文标题。

这个错误主要是由Managed C++的增量编译导致的,这是VS 2008的一个bug,在VS 2010已经修复,我使用的正式2010所以直接简单做一下Clean然后再Rebuild就可以了。如果你用的是VS 2008,请参考以下解决方案:

  1. 禁用增量编译。 In the project properties, under Configuration Properties > General, set "Enable Managed Incremental Build" to No.
  2. 给待编译的项目制定一个具体的版本。比如将 
    [assembly:AssemblyVersionAttribute("1.0.*")];

    替换为

    [assembly:AssemblyVersionAttribute("1.0.0.1")];

参考:

  • StackOverflow关于这个问题的解答:http://stackoverflow.com/questions/810827/lnk2022-metadata-operation-failed-driving-me-insane
  • 微软的bug页面:https://connect.microsoft.com/VisualStudio/feedback/details/442615/managed-incremental-build-doesnt-work-if-change-to-dependent-project-was-insignificant
原文地址:https://www.cnblogs.com/rader/p/3521919.html