I created project which is referencing x86 dll. But when I call the imported function it throws exception:
System.BadImageFormatException: An attempt was made to load a program with an incorrect format.
Program.cs:
[DllImport("lib.dll", CallingConvention = CallingConvention.StdCall)]
static extern int func(int a, int ab, int c, int d, int e);
static void Main(string[] args)
{
func(0, 0, 0, 0, 0);
}
.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<None Update="lib.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App" Version="2.0.0-preview2-25407-01" />
</ItemGroup>
</Project>`
It doesn't work if it targets netcoreapp2.0, but when I change the target framework to "net45" it works (I need netcoreapp because it's multiplatform)
Does anyone know where there could be a problem?