Hi all,
We have an existing protocol which has unit tests. If the platform target of the unit test project is set to x86, running the tests in Visual Studio succeeds. If the platform target is set to x64 or Any CPU, running the tests in VS fails. In both scenarios, when I push the protocol solution to the CI/CD pipeline, it fails and gives the same exception as it gives in VS when the platform target is set to x64 or Any CPU. The error message is the one shown below.
Error message in VS
Error message in the CI/CD pipeline
How is it possible to fix such issues?
Hi Fenta,
You need to configure the Directory.Build.props file to have something like this
<Project>
<PropertyGroup>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
</Project>
This will indicate the pipeline to use x86 for the build instead of any
Hi Fenta,
The exception you're encountering, `BadImageFormatException`, occurs when the runtime tries to load an assembly with an invalid format (e.g., 32-bit assembly loaded in a 64-bit process). You need to verify that your test project's platform target aligns with the architecture of the referenced assemblies (e.g., x86 for 32-bit assemblies, x64 for 64-bit assemblies).
When you set the Platform Target to `x86`, your unit tests compile specifically for 32-bit (x86) architecture. If you choose `x64` or `AnyCPU`, the compiled code is intended for 64-bit architecture or any available architecture, respectively.
What you need to do is ensure consistency with your protocol library and referenced assemblies.
The answer of João is a nice approach.
I hope this will help you further.