【问题标题】:Can i use a .NET DLL to solve a MONO NotImplementedException我可以使用 .NET DLL 来解决 MONO NotImplementedException
【发布时间】:2019-06-19 06:45:49
【问题描述】:

我正在尝试使用 HttpListener 设置超时

HttpListener listener;

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

但是,这会在我的 Unity 应用程序中引发 NotImplementedException。 TimeoutManager 属性是在 .NET 4.5 中添加的,在 Unity 2019.1.0a10 中(在 2018.3 中具有相同的行为)我目前正在使用当前 defaults to .NET 4.6 的 .NET 4.x 运行时。

为了验证这不是我搞砸的,我制作了一个针对 .NET 4.6 的单独 C# 项目并制作了以下程序:

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;
}

按预期运行,并分别记录 00:05:0000:10:00

现在知道它实际上可以在 Unity 之外工作,我将此程序构建到一个 DLL 中并将其包含在我的 Unity 项目中,希望调用 GetNewListener 将使用 dll 框架的 @987654330 实现@ 从而能够设置它。但这也会导致NotImplementedException

有没有办法解决它没有统一实现、使用 DLL 或自己实现的事实?还是尝试与 Unity 联系并希望他们实施的唯一解决方案?


编辑: 我被提醒 Unity 实际上使用 mono,并且在他们的 github 上查看 HttpListenerTImeoutManager 的单声道实现确实显示了 throw new NotImplementedException ();

现在我原来的问题仍然存在:有没有办法用 DLL 中的 .net 实现覆盖 mono 实现?

【问题讨论】:

  • 您在 Unity 应用程序中的目标是哪个框架?
  • @yenta 针对 .NET 4.6
  • 您使用的是哪个版本的 Unity?
  • 2019.1.0.a10,在 2018.3 中具有相同的行为。
  • 您是否将 Unity 中的 .NET 配置文件更改为更新的配置文件?您可以在播放器设置中更改 .NET 配置文件(转到编辑 > 项目设置)。

标签: c# .net unity3d mono httplistener


【解决方案1】:

我认为您可以尝试使用 Harmony 之类的方法在 Mono 的 HttpListener 上修补 TimeoutManager 方法。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-09
  • 1970-01-01
相关资源
最近更新 更多