在单声道上使用自托管nancyfx应用程序的反射错误

时间:2016-02-11 15:24:31

标签: reflection mono owin nancy self-hosting

在使用visual studio在Windows上构建并成功运行自托管的NancyFx应用程序后,我继续尝试使用mono运行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

由于某种原因,该应用尝试从HttpListener程序集初始化类System,但HttpListener仍在System.Net程序集中。我查看了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();
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

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

我不知道为什么,但我只使用mono 4.3.178与CENTOS有同样的问题。使用版本4.2.x的Debian Jesse没有问题。我用来测试的其他几个Debian Jesse盒子似乎没有4.3.x的问题。在我的情况下,我正在收听备用端口。

RedHat再次袭来:/

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

相关问题