Remy
Remy

Reputation: 5163

Can i use a .NET DLL to solve a MONO NotImplementedException

I am trying to set the timeouts on a HttpListener using

HttpListener listener;

void Foo()
{
    listener.TimeoutManager.IdleConnection = TimeSpan.FromMinutes(5);
}

However this throws a NotImplementedException inside my Unity application. The TimeoutManager property was added in .NET 4.5, In Unity 2019.1.0a10 (with the same behaviour in 2018.3) i'm currently using the .NET 4.x runtime which currently defaults to .NET 4.6.

To validate it was not me messing things up i made a seperate C# project targeted at .NET 4.6 and made the following program:

private static void Main(string[] args)
{
    HttpListener listener = GetNewListener();
    Console.WriteLine(listener.TimeoutManager.IdleConnection);

    HttpListener listener2 = new HttpListener();
    SetIdleTimeout(ref listener2, 10);
    Console.WriteLine(listener2.TimeoutManager.IdleConnection);

    Console.ReadLine();
}

public static void SetIdleTimeout(ref HttpListener listener, int timeout)
{
    listener.TimeoutManager.IdleConnection = TimeSpan.FromMinutes(timeout);
}

public static HttpListener GetNewListener()
{
    HttpListener listener = new HttpListener();

    listener.TimeoutManager.IdleConnection = TimeSpan.FromMinutes(5);
    listener.TimeoutManager.HeaderWait = TimeSpan.FromMinutes(5);
    listener.TimeoutManager.DrainEntityBody = TimeSpan.FromMinutes(5);

    return listener;
}

Which runs as expected, and logs 00:05:00 and 00:10:00 respectively.

Now knowing that it actually works outside of unity I build this programm into a DLL and included it in my Unity project, hoping that calling GetNewListener would use the dll framework's implementation of the TimeoutManager and thus be able to set it. But this too results in a NotImplementedException.

Is there a way to get around the fact it isn't implemented in unity, using DLL's, or making my own implementation? Or is the only solution to try get in contact with Unity and hope they will implement it?


Edit: I was reminded that Unity actually uses mono, and looking at the mono implementation of HttpListenerTImeoutManager on their github indeed shows the throw new NotImplementedException ();.

Now my original question still stands: Is there a way to overwrite the mono implementation with the .net implementation from the DLL?

Upvotes: 0

Views: 212

Answers (1)

yenta
yenta

Reputation: 1372

I think you could try monkey patching the TimeoutManager method on Mono's HttpListener by using something like Harmony.

Upvotes: 1

Related Questions