Hi all,
The problem is an exception being thrown when setting up a HttpClientHandler for communication with a REST API.
I have a Unity application with two bespoke DLLs. The application needs to interface to external systems, so one bespoke DLL provides the interface to the external systems and the other supplies common functionality.
The external system in question is a REST API, so when required by the application, the DLL creates a HttpClient, HttpRequestMessage etc, sends out the request, receives back JSON and hands back the data to the application.
The problem occurs when setting up comms with the external system. The code below is being executed:
class RestApiAccess
{
private static HttpClient httpClient;
public RestApiAccess()
{
ICredentials credentials = CredentialCache.DefaultCredentials;
HttpClientHandler handler = new HttpClientHandler();
handler.DefaultProxyCredentials = credentials;
httpClient = new HttpClient(handler);
}
}
There’s an exception thrown on the assignment to handler.DefaultProxyCredentials (line 10 above); “the method or operation is not implemented”.
Assuming that this means DefaultProxyCredentials isn’t implemented, this implies that there’s some sort of version mismatch in .NET DLLs, since DefaultProxyCredentials was introduced in .NET Framework 4.7.1.
I have verified that the Visual Studio projects are all targeting .NET Framework 4.7.1. I’ve also added “-r:System.Net.Http.dll” to the csc.rsp file.
The code has also been tested while targeting .NET Framework 4.7.2 and 4.8, with the same results.
Testing the DLL with a separate test harness (i.e. not Unity) and it works as expected. It’s just the Unity application that doesn’t work with the DLL.
I’m at a bit of a loss now; has anyone seen anything like this before?
Windows 10
Unity 2019.3.0f6
Visual Studio Professional 2019 version 16.7.0
.NET Framework 4.8.03761, targeting 4.7.1
Thanks!