链接器工具警告 LNK4227

元数据操作警告 (HRESULT):warning_message

合并时,链接器检测到元数据差异:

  • 一个或多个引用的程序集,其中当前正在生成程序集。

  • 编译中的一个或多个源代码文件。

例如,如果具有同名但是参数信息声明方式不同(也就是说,声明在所有编译单位中不一致)的两个全局参数,则可能会导致 LNK4227。 在每个 .obj 文件上使用 ildasm.exe /TEXT /METADATA object_file,了解类型的不同之处。

LNK4227 还用于报告源自其他工具的问题。 搜索警告消息以获取详细信息。

必须修复元数据问题才能解决警告。

示例

当引用的程序集与引用程序集的程序集不同时,会生成 LNK4227。

下面的示例生成 LNK4227:

// LNK4227.cpp
// compile with: /clr
using namespace System::Reflection;

[assembly:AssemblyDelaySignAttribute(false)];

int main() {}

然后,

// LNK4227b.cpp
// compile with: /clr LNK4227.cpp /FeLNK4227b.exe
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;

[assembly:AssemblyDelaySignAttribute(true)];
// Try the following line instead
// [assembly:AssemblyDelaySignAttribute(false)];

ref class MyClass
{
};

当错误格式的版本号传递到程序集属性时,也可以生成 LNK4227。 “*”表示法特定于 AssemblyVersionAttribute。 若要解决此警告,请仅使用版本属性中的数字,而不是 AssemblyVersionAttribute

下面的示例生成 LNK4227:

// LNK4227e.cpp
// compile with: /clr /LD /W1
using namespace System::Reflection;
[assembly:AssemblyVersionAttribute("2.3.*")];   // OK
[assembly:AssemblyFileVersionAttribute("2.3.*")];   // LNK4227
// try the following line instead
// [assembly:AssemblyFileVersionAttribute("2.3")];