【发布时间】: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