SignalR 1.x MapHubs:加载程序集时出错

时间:2013-11-12 22:03:05

标签: asp.net-mvc signalr owin

我正在尝试将SignalR 1.x集成到我的项目中(在.net 4.0上运行)。当我调用RouteTable.Routes.MapHubs()时,我遇到了一个问题。在配置任何其他路由之前,我正在Global.asax中的Application_Start中进行调用。

我最终得到这样的例外:

    [FileLoadException: API restriction: The assembly 'file:///C:\Users\Kyle\Documents\<Project>\bin\Debug\<Name>.dll' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) +102
   System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile) +34
   Owin.Loader.DefaultLoader.GetDefaultConfigurationString(Func`2 defaultTypeNames) +774
   Owin.Loader.DefaultLoader.LoadImplementation(String startupName) +177
   Owin.Loader.DefaultLoader.Load(String startupName) +45
   Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build() +167
   System.Lazy`1.CreateValue() +416
   System.Lazy`1.LazyInitValue() +152
   System.Lazy`1.get_Value() +75
   Microsoft.Owin.Host.SystemWeb.OwinApplication.get_Instance() +35
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +106
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +418
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

请注意,当我调用RouteTable.Routes.MapHubs()时,不会发生错误,而是在发出请求时发生错误。谷歌搜索透露了这个问题:

https://github.com/owin/owin-hosting/issues/17

但由于SignalR 2.x需要.net 4.5,我无法升级。

1 个答案:

答案 0 :(得分:1)

答案似乎是在不升级SignalR的情况下升级owin软件包。所以使用NuGet:

Install-Package Microsoft.Owin.Host.SystemWeb -Version 2.0.1 
Install-Package Microsoft.AspNet.SignalR.SystemWeb -Version 1.1.3