I'm trying to send a string to a Delphi COM object and expecting an answer from the object but for some reason it throws an AccessViolationException. This is the exception it throws, the description of the exception translated to english is: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Program output (with top of stack trace) :
QManservice started.
Press any key to stop.
Request to get orders received.
String received: S$GET ORDERS,Onnverwerkte uitzondering: System.AccessViolationException: Poging tot het lezen of schrijven van beveiligd geheugen. Dit duidt er vaak op dat ander geheugen is beschadigd.
bij Microsoft.Win32.Win32Native.SysStringByteLen(IntPtr bstr)
bij System.StubHelpers.BSTRMarshaler.ConvertToManaged(IntPtr bstr)
bij QMan_SafanDarley.IWLM_.Send(String Msg, String& Answer)
bij WorkLoadManagerServiceDefinitions.QManService.SendStringtoCON(String codToSend) in D:\Michael\C# Projects\QManServiceConsoleApp\OrderEditor_WCF\QManService.cs:regel 210
bij WorkLoadManagerServiceDefinitions.QManService.RequestGetOrders() in D:\Michael\CR Projects\QManServiceConsoleApp\OrderEditor_WCF\QManService.cs:regel 67 ...
This is the code that calls the COM
private string SendStringToCOM(string cmdToSend)
{
try
{
Console.WriteLine($"String received: {cmdToSend}");
if (WLM == null)
{
WLM = new WLM_();
}
string answer = string.Empty;
WLM.Send(cmdToSend, out answer);
Console.WriteLine("Answer received");
return answer;
} catch(Exception e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
return string.Empty;
}
}
This is the code in Delphi that receives the call, it sends it to another unit that does database stuff according to what command it receives.
function TWLM_.Send(const Msg: WideString; out Answer: WideString) : Integer;
begin
Result := fmProduction.AnalyzeData(Msg, 0);
end;
I should add that this works on my pc and a coworker's pc, but not on a third pc. Any suggestions on how i can resolve this?