I have two preexisting projects (C++, C# NET 4.5.2) where the C# projects calls into the C++ project. This worked perfectly until I ported the NET 4.5.2 project to NET Core. Now I get a BadImageFormatException when trying to access the assembly built from the C++ project. Is it possible to call this assembly from a NET Core assembly?
public static string CallCPlusPlusConvert(string inputFileName)
{
if (inputFileName == null) { throw new ArgumentNullException(nameof(inputFileName)); };
return SafeNativeMethods.Convert(inputFileName);
}
internal class SafeNativeMethods
{
[return: MarshalAs(UnmanagedType.BStr)]
[DllImport("CPlusPlusProject", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
internal static extern string Convert([MarshalAs(UnmanagedType.BStr)][In]string filePath);
}