在使用visual studio在windows上构建并成功运行自托管的NancyFx应用程序后,我继续尝试使用mono在Linux上运行应用程序。我能来构建解决方案(使用xbuild),但在运行应用程序时,我得到一个奇怪的错误:在单声道上自我托管的nancyfx应用程序的反射错误
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.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();
}
}
}
}
确保您使用Xamarin feed安装Mono 4.2.2。 –
@LexLi我正在使用'单声道JIT编译器版本4.3.3(master/35889d4 wo feb 10 19:30:49 CET 2016)' –
什么是您的app.config文件中列出的目标框架呢? –