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:
- Creating an x86 configuration for the entire solution.
- Adding different property groups in the C# project file for various configurations.
- 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?