I wrote a c# dll with some functions that make requests using the inbuit httpclient from the System.Net package. That dll is called from within a Delphi program, the functions are exposed via the UnmanagedExports nuget package. Everything used to work, however a few months I started to get a weird exception.
Basic exported functions work as expected, the problem occurs when httpclient's sendAsync method is called. Program execution stops and I get E0434352 External Exception. Nothing in the projects has changed, the code looks exactly how it did in the last working version, even versions compiled a year ago that were fully operational stopped working. I'm using net4.7.2, visual studio 2019.
Example of a working function:
public static int Add(int a, int b)
{
return a+b;
}
Example of a non working function:
public static int Add(int a, int b)
{
var task = Task.Run(() => client.GetStringAsync("https://random-data-api.com/api/v2/cannabis"));
task.Wait();
return a+b;
}
In this function execution stops on the task.Wait() line.
Trying to solve the issue i wrote a simple c++ wrapper to bypass the UnmanagedExports package using CLR.
That's how the wrapper looks. Works correctly for basic functions.
#pragma once
using namespace System;
using namespace CSharpNamespace;
namespace TestCPlusPlus {
public ref class ManagedCPlusPlus
{
public:
int Add(int a, int b)
{
CSharpClass^ c = gcnew CSharpClass();
int result = c->Add(a, b);
return result;
}
};
}
__declspec(dllexport) int Add(int a, int b)
{
TestCPlusPlus::ManagedCPlusPlus MCPP;
return MCPP.Add(a, b);
}
That unfortunately changed nothing, behaviour is the same.
What could be the cause? How do I go about solving the issue?