Visual Studio 2022 seems to have a problem loading x86 .dlls, in my case,("Microsoft.Dynamics.BusinessConnectorNet"), in running time using the Any CPU configuration.
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 2019 and earlier have x86 as the default for Any CPU and Visual Studio 2022 x64.
What I find very weird is that even configuring the whole solution to x86 still gives the same error, but this time in the Project instead of the x86 .dll file, while in Visual Studio 2017, the same solution is running fine.
Could not load file or assembly ‘ProjectName.Core’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
I have tried:
-
Creating an x86 & custom configuration for the whole solution.
-
Adding different property groups to the dll for different configurations in the C# Project File.
-
Forcingly removing the mismatch processor warning in the Project file.
Nothing has worked so far.
What I am expecting is what Visual Studio 2017 does as default for Any CPU to be able to run the IIS application which is working fine with the same solution.
2
Answers
It sounds like you’re confusing solution configuration with project configuration. A solution configuration (the thing you’re selecting in the drop down next to start) is just a collection of the actual configurations and architectures of each individual project inside that solution:
You set up your individual projects’ configuration from the Configuration Manager window, as seen above.
"Any CPU" always was, still is and will always be a x86 32bit option with permission to run on x86_64 machine. So changing from "Any CPU" to "x86" changes nothing.
Verify if you have Microsoft.Dynamics.BusinessConnectorNet.dll that is for 32bit or 64bit architecture. Probably now you have 64bit version and this is why it cannot be loaded.