I don't know any further and hopefully, someone can help me out (even if I cannot share code / libraries).
I have a C# .NET 5.0 WPF application , which references a C# .NET 5.0 Class library (project reference). This library communicates with a C++ CLI .NET 5.0 library (where some complex C++ code is running and I don't know, if I can change this to something like P/invoke).
You probably have heard of BadImageFormatException
which seems to be very often happening using this combination, and I googled a lot to this topic.
My problem is, that I can run the application on my development machine (from Visual Studio or compiled binaries (exe from file system)), but when I want to provide this program to someone else, who has not Visual Studio installed, this person gets this BadImageFormatException
.
I set up a VM to try out further and installed the following runtimes (the application is set to run as 32-bit):
Microsoft Visual C++ 2008 - x68 (9.0.21022)
Microsoft Visual C++ 2010 x86 Redistributable - 10.0.30319
Microsoft Visual C++ 2013 Redistributable (x64) - 12.0.30501
Microsoft Visual C++ 2013 Redistributable (x86) - 12.0.30501
Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.25.29914
Microsoft Visual C++ 2015-2019 Redistributable (x86) - 14.25.29914
Microsoft Windows Desktop Runtime - 5.0.5 (x64)
Microsoft Windows Desktop Runtime - 5.0.5 (x86)
As the application worked fine on my machine, I think I can exclude issues regarding 32-bit / 64-bit mismatchings (which is often the source of the BadImageFormatException
), so maybe there is just something missing in terms of runtimes / redistributables /...
In addition I should mention, that I never had programmed with C++ before, therefore I don't know the restrictions / requirements to deploy these kinds of applications.
I was able to fix it by myself!
In the *.vcxproj
file, I accidentally made it to set the Release
configuration to <UseDebugLibraries>true</UseDebugLibraries>
, changing this value to false solved all problems automagically.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CLRSupport>NetCore</CLRSupport>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.