When building or packaging a .NET desktop application—such as a WPF, WinForms, or Windows Application Packaging Project (.wapproj)—encountering build warning MSB3270 is a common obstacle. It typically surfaces when your primary application targets Any CPU (MSIL) while referencing an assembly compiled explicitly for x86 (32-bit) or x64 (64-bit).
Left unresolved, this mismatch frequently leads to a System.BadImageFormatException at runtime or causes installer packaging workflows (such as MSIX or Inno Setup builds) to fail. This guide explains the root cause behind MSB3270 and provides actionable solutions to align your build configurations cleanly.
Understanding the Error Message
A typical MSB3270 build warning looks like this:
There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "...\bin\x86\Debug\net8.0-windows\win-x86\MyLibrary.dll", "x86". This mismatch may cause runtime failures.
What Do MSIL, x86, and x64 Mean?
MSIL(Microsoft Intermediate Language / Any CPU): Indicates that the compiled assembly is architecture-neutral. At runtime, the Common Language Runtime (CLR) compiles the IL code into native machine instructions matching the host operating system—running as a 64-bit process on 64-bit Windows and a 32-bit process on 32-bit Windows.x86: Forces the assembly to compile and run strictly as a 32-bit process.x64: Forces the assembly to compile and run strictly as a 64-bit process.
Why Does the Mismatch Happen?
On modern 64-bit Windows machines, an Any CPU (.NET 6/7/8+) executable runs as a 64-bit process by default. Windows operating systems do not allow a 64-bit process to load a 32-bit (x86) native DLL or a mixed-mode assembly directly into the same memory space. When the CLR attempts to load that x86 dependency at runtime, the application crashes immediately with a BadImageFormatException.
This issue commonly occurs when:
You reference a legacy third-party library or COM wrapper compiled exclusively for 32-bit (
x86).One project in your multi-project solution was accidentally set to
x86while the startup project remained onAny CPU.A Windows Application Packaging Project (
.wapproj) is set tox64orAny CPUwhile packaging a desktop application built forx86.
Solution 1: Align Project Platforms via Configuration Manager (Recommended)
The cleanest and safest approach is to configure your main project—and any packaging projects—to match the exact processor architecture of your dependency.
Open your solution in Visual Studio.
In the top menu bar, navigate to Build > Configuration Manager (or right-click the Solution in Solution Explorer and select Configuration Manager).
Check the Active solution platform dropdown at the top right:
If
x86is not listed, click<New...>, choosex86from the new platform dropdown, copy settings fromAny CPU, and click OK.
In the Project contexts table, verify that every project—including your main desktop app, class libraries, and any Windows Application Packaging Project—has its Platform column set to
x86.Ensure the Build checkbox is checked for all required projects.
Click Close, then run Build > Rebuild Solution.
Solution 2: Enforce PlatformTarget in the .csproj File
If you manage builds through CI/CD pipelines (such as GitHub Actions, Azure DevOps, or Jenkins) or prefer declarative project configurations, you can hardcode the architecture directly inside your .csproj file.
Right-click your project in Solution Explorer and select Edit Project File.
Locate the primary
<PropertyGroup>and add the<PlatformTarget>and<RuntimeIdentifier>properties:
XML
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<PlatformTarget>x86</PlatformTarget>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>
</Project>Save the file and rebuild the project. Adding
<RuntimeIdentifier>win-x86</RuntimeIdentifier>also ensures thatdotnet publishoutputs the exact 32-bit runtime dependencies required for packaging.
Solution 3: Recompile the Referenced Project as Any CPU
If the x86 DLL (MyLibrary.dll) is another project within your own solution rather than a third-party binary, you do not need to restrict your entire application to 32-bit:
Open Configuration Manager.
Locate the referenced class library project.
Change its Platform from
x86toAny CPU.Delete the existing
binandobjfolders in both projects to clear stalewin-x86build artifacts.Rebuild the solution. Both projects will now compile as
MSILand execute natively in 64-bit mode on modern systems.
Special Consideration: Windows Application Packaging Projects (.wapproj)
When generating an MSIX installer using a Windows Application Packaging Project, architecture alignment is strictly enforced during the Create App Packages wizard:
Your
.wapprojfile must target the exact same architecture (x86orx64) as the entry-point desktop application.If your desktop app is locked to
x86, uncheckx64andARM64in the Select and Configure Packages step of the MSIX packaging wizard, leaving onlyx86selected.
Best Practices to Prevent Architecture Mismatches
Standardize Solution Configurations: Keep all projects in a solution aligned under consistent
x64orx86solution platforms rather than mixingAny CPUwith explicit architectures.Clean Build Artifacts When Switching Targets: Always clean
bin/andobj/directories after changingPlatformTargetso MSBuild does not resolve cached DLLs from previous architecture folders (such asbin\x86\Debug).Verify CLI Publish Flags: When publishing via the .NET CLI for installers like Inno Setup or WiX, explicitly pass the matching runtime flag (
dotnet publish -c Release -r win-x86) so the bundled native host matches your compiled assemblies.

Join the conversation! Your thoughts help the community grow.