Two different reasons :
The first is that the running of the program does not match the number of platform system bits, the second one is the Damned vs whole ...
Typically occurs under the following three scenarios.
C # calls 32-bit C + + *.dll on a 1.64-bit system
When IIS publishes an *.dll application that contains 32-bit on a 2.64-bit system
Writing C + + *.dll on a 3.64-bit system, calling through C # on a 64-bit system, may or may not succeed, and failure is reported as BadImageFormatException exception, and it is also the second most likely case. It's the fucking vs.
Here's how to fix it:
1.vs under the 64-bit system, when compiling debugging a C + + API, Error: Unhandled badimageformatexception attempted to load a program that is not properly formatted. (Exception from hresult:0x8007000b)
See:
The reason for this is that the API was developed under the three-bit system, and in the development of the system, the built target platform needs to be set to X86.
the method is :
in Solution Explorer on the right, right-click on the item's properties. In the Properties window, select "Build"--"target platform" dropdown to select "X86". See:
and then save the recompile
Cause: the communication between assemblies is either full of 64-bit environments or full of 32-bit environments. cannot be mixed access. Otherwise, the error "attempting to load an improperly formatted program" will appear;
The solution is to turn on 32-bit compatibility for the program pool of the publishing site , such as:
3. if the above is not resolved , that is the problem with C # Engineering in VS , open the corresponding project file (*. Csproj), such as the <Prefer32Bit>false</Prefer32Bit> node
The following is an explanation of MSDN :
Csharpprojectconfigurationproperties6.prefer32bit Property
Gets or sets a flag that indicates whether the preferred 32-bit platform.
Namespaces: VSLangProj110
Assembly: VSLangProj110(in VSLangProj110.dll )
Grammar
C#
BOOL Prefer32bit {get; set;}
Property value
Type: System.Boolean
Returns a flag that represents a 32-bit preference. Returns True if 32 bits is preferred. Otherwise, returns false.
An attempt was made to load a program that is not properly formatted. (Exception from hresult:0x8007000b)