How do I fix the Visual Studio compile error, “mis

2019-01-01 17:01发布

I'm new to project configuration in Visual Studio 2010, but I've done some research and still can't quite figure this issue out. I have a Visual Studio solution with a C++ DLL referencing the C# DLL. The C# DLL references a few other DLLs, some within my project and some external. When I try to compile the C++ DLL, I get this warning:

warning MSB3270: There was a mismatch between the processor architecture of the project being build "MSIL" and the processor architecture of the reference "[internal C# dll]", "x86".

It tells me to go to Configuration Manager to align my architectures. The C# DLL is set up with platform target x86. If I try to change this to something else, like Any CPU, it complains because one of the external DLLs it depends on has platform target x86.

When I look at Configuration Manager it shows the Platform for my C# DLL as x86 and for my C++ project as Win32. This seems like the right setup; surely I don't want the project for my C++ project to have platform set to x64, which is the only other option presented.

What am I doing wrong here?

18条回答
牵手、夕阳
2楼-- · 2019-01-01 17:14

I had this problem today and just looking the building configurations in Visual Studio wasn't helping because it showed Any CPU for both the project that wasn't building and the referenced project.

I then looked in the csproj of the referenced project and found this:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>

Somehow this PlatformTarget got added in the middle of a config change and the IDE didn't seem to see it.

Removing this line from the referenced project solved my problem.

查看更多
冷夜・残月
3楼-- · 2019-01-01 17:17

I had the same problem with SQLite opening connection, and using the Nuget and installing the component used in project (SQLite) fixed it! try installing your component this way and check the result

查看更多
刘海飞了
4楼-- · 2019-01-01 17:19

I had a very similar warning in my build. My projects were set to target .NET 4.5, on the build server the Windows 8.1 SDK (for .NET 4.5.1) was installed. After updating my projects to target .NET 4.5.1 (wasn't a problem for me, was for a completely new application), I didn't receive the warning anymore...

查看更多
流年柔荑漫光年
5楼-- · 2019-01-01 17:21

I solved this warning changing "Configuration Manager" to Release (Mixed Plataform).

查看更多
后来的你喜欢了谁
6楼-- · 2019-01-01 17:22

If your C# DLL has x86-based dependencies, then your DLL itself is going to have to be x86. I don't really see a way around that. VS complains about changing it to (for example) x64 because a 64-bit executable can't load 32-bit libraries.

I'm a little confused about the configuration of the C++ project. The warning message that was provided for the build suggests that it was targeted for AnyCPU, because it reported the platform that it targeted was [MSIL], but you indicated that the configuration for the project was actually Win32. A native Win32 app shouldn't involve the MSIL - although it would likely need to have CLR support enabled if it is interacting with a C# library. So I think there are a few gaps on the information side.

Could I respectfully ask you review and post a bit more detail of the exact configuration of the projects and how they are inter-related? Be glad to help further if possible.

查看更多
闭嘴吧你
7楼-- · 2019-01-01 17:23

This is a very stubborn warning and while it is a valid warning there are some cases where it cannot be resolved due to use of 3rd party components and other reasons. I have a similar issue except that the warning is because my projects platform is AnyCPU and I'm referencing an MS library built for AMD64. This is in Visual Studio 2010 by the way, and appears to be introduced by installing the VS2012 and .Net 4.5.

Since I can't change the MS library I'm referencing, and since I know that my target deployment environment will only ever be 64-bit, I can safely ignore this issue.

What about the warning? Microsoft posted in response to a Connect report that one option is to disable that warning. You should only do this is you're very aware of your solution architecture and you fully understand your deployment target and know that it's not really an issue outside the development environment.

You can edit your project file and add this property group and setting to disable the warning:

<PropertyGroup>
  <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>
查看更多
登录 后发表回答