web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Mismatch Between Processor Architecture Error with x86 DLL in Visual Studio 2022

(1) ShareShare
ReportReport
Posted on by 14

I'm encountering an issue in Visual Studio 2022 where it fails to load x86 DLLs (specifically Microsoft.Dynamics.BusinessConnectorNet) at runtime when using the Any CPU configuration, the DLL is added as reference.

<Reference Include="Microsoft.Dynamics.BusinessConnectorNet, Version=6.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\Libraries\Microsoft.Dynamics.BusinessConnectorNet.dll</HintPath>
</Reference>

Could not load file or assembly 'Microsoft.Dynamics.BusinessConnectorNet' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

I understand that Visual Studio 2022 uses x64 as the default for Any CPU, unlike Visual Studio 2019 and earlier versions, which defaulted to x86. However, even after changing the entire solution's configuration to x86, I still get the same error. The error shifts from the x86 DLL to one of the solution's projects. The same solution works perfectly fine in Visual Studio 2017.

Here is the error message I received:

Could not load file or assembly 'ProjectName' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Steps I Have Tried:

  1. Creating an x86 configuration for the entire solution.
  2. Adding different property groups in the C# project file for various configurations.
  3. Suppressing the processor architecture mismatch warning in the project file.

None of these steps have resolved the issue.

Expected Behavior:

I expect the solution to behave similarly to Visual Studio 2017, where Any CPU allows the IIS application to run properly without any architecture mismatch errors.

Questions:

  • Is there a way to replicate Visual Studio 2017's behavior for Any CPU in Visual Studio 2022?
  • Are there additional settings or configurations I might have missed to ensure proper loading of x86 DLLs in Visual Studio 2022?
Categories:
I have the same question (0)
  • Suggested answer
    CU23121052-0 Profile Picture
    14 on at
    Mismatch Between Processor Architecture Error with x86 DLL in Visual Studio 2022
    @Martin Dráb your insight was indeed correct, it was an IIS Version problem in my case I needed to run the x86 version instead of the default for Visual Studio 2022, changing this in the Start Project properties fixed the issue.

  • Martin Dráb Profile Picture
    236,025 Most Valuable Professional on at
    Mismatch Between Processor Architecture Error with x86 DLL in Visual Studio 2022
    All right, so we're talking about loading to IIS Express, not Visual Studio. Maybe it's about the version of IIS Express and not about Visual Studio. You could test that. For example, you could take the application from your DEV box with VS 2022, copy it to the DEV box with VS 2009 and run both in IIS Express from command line. If the app built in VS 2019 works and the new one doesn't, you'll know that something is wrong with the app as such, while if both work, you'll have a proof that the application is fine and the problem lies elsewhere.
     
    Regarding the warning, I believe that it used to be there even in older versions in VS, but it still ran. If so, the warning isn't the reason why the assembly can't be loaded. You can use the assembly binding log viewer to learn more about what failed to load (as the error says, it could be an unidentified dependency, not BusinessConnectorNet assembly itself).
  • CU23121052-0 Profile Picture
    14 on at
    Mismatch Between Processor Architecture Error with x86 DLL in Visual Studio 2022
    The name of the Project was not relevant in this case, that suffix was there to point out the "Core" Project in the WebService application I am trying to run with Visual Studio 2022.

    The target version is : <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
     
    The main issue here that I cannot understand is why the solution works and runs fine as IIS Express service in Visual Studio 2017 and Visual Studio 2019. Still, when trying to run it in Visual Studio 2022 I get the warning:

    "There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Microsoft.Dynamics.BusinessConnectorNet, Version=6.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project."

    After in runtime trying to run the application I got the errors explained above:

    Could not load file or assembly 'Microsoft.Dynamics.BusinessConnectorNet' or one of its dependencies
  • Martin Dráb Profile Picture
    236,025 Most Valuable Professional on at
    Mismatch Between Processor Architecture Error with x86 DLL in Visual Studio 2022
    I'm not getting what you mean by "Visual Studio 2022 fails to load a DLL at runtime". Could you tell us a bit more about what you're doing and when it fails? You mentioned runtime and IIS, therefore it sounds like you're trying to load your project somewhere on IIS, but that would mean that your question isn't about loading in VS at all.
     
    I have no idea what is ProjectName.Core, but doesn't the ".Core" suffix suggests that it's built for .NET Core and not .NET Framework? What target framework are you using for your project?
     
    By the way, Any CPU was the default target architecture already in VS 2005, therefore it's not a new thing in VS 2022.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 846 Super User 2025 Season 2

#2
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 838

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 818 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans