我正在将解决方案从 MSVS2005 移植到 MSVS2012。这些项目在 C++ .NET 中,但也使用自制的本地 C++ 库。我们使用 2005 构建项目没有问题,但现在,我无法使用 2012 构建项目。我收到以下错误消息:
MyFile.obj:错误 LNK2022:元数据操作失败 (801311E4):重复的托管类型具有不同的可见性。
这是什么意思?你需要什么信息来帮助我?
谢谢你的帮助?
最佳答案
我有同样的问题,并且确实有 dom_beau 的回答中描述的相同情况,所以我很确定我也有相同的根本原因。然而,为了能够解决这个错误,我必须找到实际的违规类(有一些,而且错误消息对你找到它们几乎没有帮助!)。
因此,我编写了以下 LINQ 查询,该查询查找在多个 *.obj 文件中定义的所有具有冲突可见性的类。它可能对某人有用,所以我将其发布在这里。
// Analyze text files produced by ildasm when given *.obj files.
// Use "for %1 in (*.obj) do ildasm /text %1 > %1-ildasm.txt" to produce the files.
from file in Directory.GetFiles(@"your project's intermediate folder")
where file.EndsWith("-ildasm.txt")
let lines = File.ReadAllLines(file)
from i in Enumerable.Range(0, lines.Count() - 1)
where lines[i].Contains("TypDefName:")
let type = lines[i].Substring(16,lines[i].IndexOf(" (")-17)
let flags = lines[i+1]
group new {file, flags} by type into g
where g.Select(t=>t.flags).Distinct().Count() > 1
select g
关于.net - MSVS 2012 上的 LNK2022(重复的托管类型具有不同的可见性),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12645105/