运行SignalR自宿主示例会在最新的mono dev分支中引发异常 [英] Running SignalR self-host samples throws exception with latest mono dev branch

查看:76
本文介绍了运行SignalR自宿主示例会在最新的mono dev分支中引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上使用Mono,示例Microsoft.AspNet.SignalR.Mono位于 https://github.com/SignalR/SignalR 似乎可以使用稳定版本的mono来工作,但不能与最新的开发分支(3.99)一起使用.有人遇到这个吗?我收到以下异常:

Using Mono on Linux, the sample Microsoft.AspNet.SignalR.Mono found at https://github.com/SignalR/SignalR seems to work using the stable release of mono but not with the latest development branch (3.99). Anyone encounter this? I get the following exception:

Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the
target of an invocation. ---> System.InvalidProgramException: Invalid IL code
in (wrapper delegate-invoke)
<Module>:invoke_callvirt_CancellationTokenRegistration_CancellationToken&_Action`1<object>_object
(System.Threading.CancellationToken&,System.Action`1<object>,object): IL_004f:
castclass 0x00000007


  at
Microsoft.AspNet.SignalR.Infrastructure.CancellationTokenExtensions.SafeRegister
(CancellationToken cancellationToken, System.Action`1 callback, System.Object
state) [0x00000] in <filename unknown>:0 
  at
Microsoft.AspNet.SignalR.Hosting.HostDependencyResolverExtensions.InitializeResolverDispose
(IDependencyResolver resolver, CancellationToken hostShutdownToken) [0x00000]
in <filename unknown>:0 
  at
Microsoft.AspNet.SignalR.Hosting.HostDependencyResolverExtensions.InitializeHost
(IDependencyResolver resolver, System.String instanceName, CancellationToken
hostShutdownToken) [0x00000] in <filename unknown>:0 
  at Owin.OwinExtensions.UseSignalRMiddleware[PersistentConnectionMiddleware]
(IAppBuilder builder, System.Object[] args) [0x00000] in <filename unknown>:0 
  at Owin.OwinExtensions.RunSignalR (IAppBuilder builder, System.Type
connectionType, Microsoft.AspNet.SignalR.ConnectionConfiguration configuration)
[0x00000] in <filename unknown>:0 
  at Owin.OwinExtensions.RunSignalR[RawConnection] (IAppBuilder builder,
Microsoft.AspNet.SignalR.ConnectionConfiguration configuration) [0x00000] in
<filename unknown>:0 
  at Owin.OwinExtensions.RunSignalR[RawConnection] (IAppBuilder builder)
[0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.SelfHost.Samples.Startup.<Configuration>b__0 (IAppBuilder
map) [0x00000] in <filename unknown>:0 
  at Owin.MapExtensions.Map (IAppBuilder app, PathString pathMatch,
System.Action`1 configuration) [0x00000] in <filename unknown>:0 
  at Owin.MapExtensions.Map (IAppBuilder app, System.String pathMatch,
System.Action`1 configuration) [0x00000] in <filename unknown>:0 
  at Microsoft.AspNet.SelfHost.Samples.Startup.Configuration (IAppBuilder app)
[0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke
(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[] parameters,
System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[] parameters,
System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[]
parameters) [0x00000] in <filename unknown>:0 
  at Owin.Loader.DefaultLoader+<>c__DisplayClass12.<MakeDelegate>b__b
(IAppBuilder builder) [0x00000] in <filename unknown>:0 
  at Owin.Loader.DefaultLoader+<>c__DisplayClass1.<LoadImplementation>b__0
(IAppBuilder builder) [0x00000] in <filename unknown>:0 
  at Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveApp
(Microsoft.Owin.Hosting.Engine.StartContext context) [0x00000] in <filename
unknown>:0 
  at Microsoft.Owin.Hosting.Engine.HostingEngine.Start
(Microsoft.Owin.Hosting.Engine.StartContext context) [0x00000] in <filename
unknown>:0 
  at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start
(Microsoft.Owin.Hosting.StartOptions options) [0x00000] in <filename unknown>:0 
  at Microsoft.Owin.Hosting.Starter.HostingStarter.Start
(Microsoft.Owin.Hosting.StartOptions options) [0x00000] in <filename unknown>:0 
  at Microsoft.Owin.Hosting.WebApp.StartImplementation (IServiceProvider
services, Microsoft.Owin.Hosting.StartOptions options) [0x00000] in <filename
unknown>:0 
  at Microsoft.Owin.Hosting.WebApp.Start (Microsoft.Owin.Hosting.StartOptions
options) [0x00000] in <filename unknown>:0 
  at Microsoft.Owin.Hosting.WebApp.Start[Startup]
(Microsoft.Owin.Hosting.StartOptions options) [0x00000] in <filename unknown>:0 
  at Microsoft.Owin.Hosting.WebApp.Start[Startup] (System.String url) [0x00000]
in <filename unknown>:0 
  at Microsoft.AspNet.SelfHost.Samples.Program.Main (System.String[] args)
[0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. --->
System.InvalidProgramException: Invalid IL code in (wrapper delegate-invoke)
<Module>:invoke_callvirt_CancellationTokenRegistration_CancellationToken&_Action`1<object>_object
(System.Threading.CancellationToken&,System.Action`1<object>,object): IL_004f:
castclass 0x00000007

推荐答案

如果IsRunningMono为true,我最终要做的是在ResolveRegisterDelegate()中返回后备寄存器:

What I eventually went with was to return the fallback register in ResolveRegisterDelegate() if IsRunningMono is true:

if (MonoUtility.IsRunningMono)
    return fallback;

try
{
    methodInfo = typeof(CancellationToken).GetMethod("InternalRegisterWithoutEC",
                                                             BindingFlags.NonPublic | BindingFlags.Instance,
                                                             binder: null,
                                                             types: new[] { typeof(Action<object>), typeof(object) },
                                                             modifiers: null);

}
catch
{
    // Swallow this exception. Being extra paranoid, we don't want anything to break in case this dirty
    // reflection hack fails for any reason
}

我注意到这是在较早的mono稳定版本中发生的,因为GetMethod("InternalRegisterWithoutEC")返回的是null,而在最新的mono的dev分支中没有返回null.

I noticed that this was happening in the earlier stable release of mono because the GetMethod("InternalRegisterWithoutEC") was returning null and did NOT return null with the latest dev branch of mono.

这篇关于运行SignalR自宿主示例会在最新的mono dev分支中引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆