Share via

Unable to switch from AnyCPU (x86) to x64 after migrating .NET Framework 4.7.2 project to .NET 8

Drusti Kumar 20 Reputation points
2025-09-29T07:01:41.71+00:00

Hello Team,

I have migrated my Windows Forms application from .NET Framework 4.7.2 (where it was running in Debug | AnyCPU mode, effectively x86) to .NET 8 (Windows). Now, I want to run it in Debug | x64, but I am facing issues: (Visual Studio 2022)

• In Configuration Manager, even after adding a new x64 platform, it still shows AnyCPU for my project.

• I also tried modifying the .csproj file to set <PlatformTarget>x64</PlatformTarget>, but it continues to show AnyCPU in Configuration Manager.

• When I try to run the application, it is breaking at runtime .

My questions are:

  1. Why does Configuration Manager keep defaulting to AnyCPU even after adding x64?
  2. Is there a different way to properly target x64 in .NET 8 compared to .NET Framework 4.7.2?
  3. What is the recommended approach for forcing a migrated WinForms app to run as x64 only?

Any guidance would be greatly appreciated.

Thanks & Regards

Developer technologies | .NET | .NET Runtime

1 answer

Sort by: Most helpful
  1. Varsha Dundigalla(INFOSYS LIMITED) 4,865 Reputation points Microsoft External Staff
    2025-09-30T10:36:14.2533333+00:00

    Thank you for reaching out.

    When migrating from .NET Framework (classic projects) to .NET 8 (SDK-style projects), the way platform targets are handled is fundamentally different:

    1. In .NET Framework
    • Configuration Manager and the .sln file controlled platform targets like x86, x64, and AnyCPU.
    • Changing the platform in Configuration Manager reliably changed how the project compiled.
    1. In .NET 8 SDK-style Projects
    • Projects default to AnyCPU unless <PlatformTarget> is explicitly set in the .csproj.
    • Configuration Manager is mostly a UI convenience and doesn’t always propagate platform changes across all projects.
    • Even after adding x64, some projects may still show AnyCPU due to this behavior.

    Additional Insight: .sln File Behavior

    The .sln file may retain AnyCPU as the default platform unless manually updated. This can cause inconsistencies between the solution-level platform and individual project-level platforms. Visual Studio may not automatically sync these settings, especially in SDK-style projects [1].

    Recommended Fixes

    1. Manually Add x64 in Configuration Manager (for every project)
    2. Open Configuration Manager.
    3. For each project showing Any CPU, click the Platform dropdown.
    4. Select ** → choose x64 → copy settings from Any CPU.
    5. Do this for both Debug and Release.
    6. Save, close, and reopen Visual Studio.

    This ensures all projects in the solution have an explicit x64 platform entry [1].

    1. Update .csproj Files (most reliable for SDK projects)

    Add this to each project’s .csproj:

    <PropertyGroup>
      <PlatformTarget>x64</PlatformTarget>
      <Prefer32Bit>false</Prefer32Bit>
      <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    </PropertyGroup>
    

    Or conditionally for Debug/Release:

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
      <PlatformTarget>x64</PlatformTarget>
    </PropertyGroup>
     
    

    This overrides the default AnyCPU and forces the compiler to target x64 [2] [3].

    1. Clean and Rebuild

    After updating both Configuration Manager and .csproj files:

    • Delete all bin and obj folders.
    • Clean the solution.
    • Rebuild → all outputs should now be x64.

    Recommended Approach for Migrated WinForms Apps

    If you want to enforce x64 only (recommended for native interop):

    <PropertyGroup>
      <PlatformTarget>x64</PlatformTarget>
      <Prefer32Bit>false</Prefer32Bit>
      <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    </PropertyGroup>
    

    If you need flexibility, you can still allow AnyCPU alongside x64, but be explicit in your .csproj.

    In Short

    • .NET 8 SDK-style projects don’t fully rely on Configuration Manager — you must set PlatformTarget in .csproj.
    • Ensure all projects in your solution have consistent x64 settings in both Configuration Manager and .csproj.
    • Clean + rebuild ensures everything actually compiles for x64.

    Microsoft References

    Let me know if you need any further help with this. We'll be happy to assist.

    If you find this helpful, please mark this as answered.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.