2016-02-11 22 views
0

在使用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(); 
      } 
     } 
    } 
} 
+0

确保您使用Xamarin feed安装Mono 4.2.2。 –

+0

@LexLi我正在使用'单声道JIT编译器版本4.3.3(master/35889d4 wo feb 10 19:30:49 CET 2016)' –

+0

什么是您的app.config文件中列出的目标框架呢? –

回答

0

没错,错的的确组装。

林不知道为什么,但我只与使用单声道4.3.178 CENTOS相同的问题。 Debian Jesse使用版本4.2.x没有问题。我用来测试的其他几个Debian Jesse框似乎对4.3.x没有任何问题。在我的情况下,我正在监听备用端口。

RedHat的打击还是那句话:/

更深的堆栈跟踪到IL似乎表明您建立在单一机器上的GCC,也是构建要领包有一些非常过时的库,甚至编译器。我惊讶地发现警告的数量接近70,000,而不是典型的400,这取决于你拥有的库的多样性。我有大约10个小时的时间来解决这个问题,所以希望它不会太坏。

+0

我刚刚更新到单声道4.4.0(需要最新版本的Xamarin Studio),现在有同样的问题。我在Mac上。你有没有设法解决这个问题? – Corstiaan

相关问题