LNK2022 (Duplicate managed types have different visibilities) on MSVS 2012

后端 未结 5 692
悲&欢浪女
悲&欢浪女 2021-01-11 19:09

I\'m porting a solution from MSVS2005 to MSVS2012. The projects are in C++ .NET but use homemade native C++ libraires too. We had no problem building the projects with 2005

5条回答
  •  星月不相逢
    2021-01-11 20:03

    I had the same problem, and indeed had the same condition described in dom_beau's answer, so I'm pretty sure I had the same underlying cause as well. However, to be able to resolve the error, I had to find the actual offending classes (there were a few, and the error messages do little to help you find them!).

    So I wrote the following LINQ query which finds all classes defined in multiple *.obj files with conflicting visibilities. It may be useful to someone, so I'm posting it here.

    // 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
    

提交回复
热议问题