Issue Definition: LNK2022
Customer migrated a project from VS2008/VS2010 to VS2012/VS2013. On compilation he get’s the following error: error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent.
Cause for LNK2022
On checking project properties we saw that the platform toolset was set to V120 and the target framework version was set to v3.5. This is basically an untested and unsupported combination. When this combination is set the linker will error out mostly with below message…
Error LNK2022: metadata operation failed (80131195) : Custom attributes are not consistent
Resolution for LNK2022
v120 requires a compatible .net framework version: For example, to target the .NET Framework 4.5, you must use a compatible platform toolset such as Visual Studio 2013 (v120) or Visual Studio 2012 (v110).
How to change <TargetFrameworkVersion>
- In Visual Studio, in Solution Explorer, open the shortcut menu for your project and then choose Unload project. This unloads the project (.vcxproj) file for your project…
- Open the shortcut menu for the project again…
- Select “Edit ProjectName.vcxproj”.
- In the project file, locate the entry for the target Framework version. For example, if your project is designed to use the .NET Framework 4.5, locate <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> in the <PropertyGroup Label=”Globals”> element of the <Project> element.
<PropertyGroup Label=”Globals”>
<ProjectGuid>{FC41C62B-4B0E-4357-B913-251F12FE4DCD}</ProjectGuid>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<Keyword>Win32Proj</Keyword>
<RootNamespace>ConsoleApplication2</RootNamespace>
</PropertyGroup>
<Import Project=”$(VCTargetsPath)\Microsoft.Cpp.Default.props” />
<PropertyGroup Condition=”‘$(Configuration)|$(Platform)’==’Debug|Win32′” Label=”Configuration”>
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<CLRSupport>true</CLRSupport>
</PropertyGroup> - Save the project file, File->Save or use shortcut Ctrl + S.
- In the solution explorer right click on the project file again and select the option “Reload Project” as shown below…
Say yes to below prompt…
- Now your framework version will be set to v4.5. You can verify this via Project Property Dialog box…
- Verified!
References
How to: Modify the Target Framework and Platform Toolset
Visual Studio 2013 Compatibility
.NET Framework SDKs and Targeting Packs for Visual Studio 2013
C++ Native Multi-Targeting