I have a C# Application (VS 2017 .Net 4.6.1) that passes a string to a Delphi DLL (Delphi 10.2) which processes the inputs and returns outputs.
I am receiving a FaultExecutionEngineError "Common sources of this bug include user marshaling errors for COM-interop or PInvoke".
I have a few questions:
If My Delphi DLL is compiled with IMAGE_FILE_LARGE_ADDRESS_AWARE will my c# App also need to be compiled with editbin /largeaddressaware?
Could my Delphi DLL Loading child DLLs be causing the FaultExecutionEngineError? In my test I am not actually calling anything in the child DLLs except their initial startup.
Is there a tool to maybe debug these in Delphi?
Delphi:
procedure Go(Inputs : WideString; var Rates : WideString); stdcall;
begin
Rates := Inputs + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
end;
c#
[DllImport("DelphiDLL.dll",
CharSet = CharSet.Unicode,
EntryPoint = "LoadLibraries")]
public static extern void _LoadLiabraries(
out int res);
[DllImport("DelphiDLL.dll",
CharSet = CharSet.Unicode,
EntryPoint = "Go")]
public static extern void _Go(
[MarshalAs(UnmanagedType.BStr)]
string Inputs,
[MarshalAs(UnmanagedType.BStr)]
out string Outputs);
public static string CallGo(string Inputs) {
string outputs;
_Go(Risk, out outputs);
return outputs;
}
If I run this code:
{
string inputs = "Test Input";
int i = 0;
do {
string output = CallGo(inputs);
Console.WriteLine(String.Format("{0} {1} {2}", i, inputs, output)
} while (i++ < 10000)
}
The I don't get the message but if I run this:
{
int llres = 0;
_LoadLibraries(llres);
string inputs = "Test Input";
int i = 0;
do {
string output = CallGo(inputs);
Console.WriteLine(String.Format("{0} {1} {2}", i, inputs, output)
} while (i++ < 10000);
}
I get the error after N tries. The Number of tries has been consistent between tries. If I change the code the Number of successful tries has changed.