【问题标题】:Reflection error with self-hosted nancyfx app on mono单声道上自托管的 nancyfx 应用程序的反射错误
【发布时间】:2016-05-14 07:59:30
【问题描述】:

在使用 Visual Studio 在 Windows 上构建并成功运行自托管 NancyFx 应用程序后,我继续尝试使用单声道在 linux 上运行该应用程序。我能够构建解决方案(使用 xbuild),但是在运行应用程序时出现一个奇怪的错误:

Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 
System.TypeLoadException: Could not load type 'System.Net.HttpListener'     
from assembly 'System, Version=4.0.0.0, Culture=neutral,       
PublicKeyToken=b77a5c561934e089'.
at Microsoft.Owin.Host.HttpListener.OwinServerFactory.Initialize (IDictionary`2 properties) <0x413ae4f0 + 0x000eb> in <filename unknown>:0

由于某种原因,应用程序尝试从 System 程序集初始化类 HttpListener,但 HttpListener 存在于 System.Netassembly 中。我查看了 GAC 文件夹,发现 System.Net 按预期存在。我将副本移动到了应用程序的其他依赖项所在的 bin 文件夹,但这并没有解决问题。任何帮助,将不胜感激!!

这是我的 OWIN 相关代码:

// Startup.cs 
using Owin;

namespace MyApp
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
             app.UseNancy();
        }
    }
}

// Program.cs
using System;
using Microsoft.Owin.Hosting;

namespace MyApp
{
    public class Program
    {
        static void Main(string[] args)
        {
            var url = "http://127.0.0.1:8080/";
            using (WebApp.Start<Startup>(url))
            {
                Console.WriteLine("Running on {0}", url);
                Console.WriteLine("Press enter to exit");
                Console.ReadLine();
            }
        }
    }
}

【问题讨论】:

  • 确保使用 Xamarin 源安装 Mono 4.2.2。
  • @LexLi 我正在使用Mono JIT compiler version 4.3.3 (master/35889d4 wo feb 10 19:30:49 CET 2016)
  • 那么你的 app.config 文件中列出的目标框架是什么?

标签: reflection mono owin nancy self-hosting


【解决方案1】:

是的,确实是错误的组装。

我还不确定为什么,但我在 CENTOS 上遇到了同样的问题,只使用单声道 4.3.178。使用 4.2.x 版本的 Debian Jesse 没有问题。我用来测试的其他几个 Debian Jesse 盒子似乎与 4.3.x 没有问题。就我而言,我正在侦听备用端口。

RedHat 再次出击:/

对 IL 的更深层次的堆栈跟踪似乎表明您构建 mono 的机器上的 gcc 以及 build essentials 包有一些非常过时的库甚至编译器。我很惊讶地看到警告的数量接近 70,000 个,而不是典型的 400 个,具体取决于您拥有的库的多样性。我有大约 10 个小时的时间来解决这个问题,所以希望它不会太糟糕。

【讨论】:

  • 我刚刚更新到 mono 4.4.0(最新版本的 Xamarin Studio 需要),现在遇到了同样的问题。我在 Mac 上。你解决了这个问题吗?
猜你喜欢
  • 2022-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-17
  • 1970-01-01
  • 2018-05-22
  • 2014-10-10
相关资源
最近更新 更多