简体   繁体   English

信号器装配加载问题OWIN

[英]Signalr assembly loading issue OWIN

I'm getting this error when attempting to load classes in the Microsoft.AspNet.SignalR.Owin assembly. 尝试在Microsoft.AspNet.SignalR.Owin程序集中加载类时出现此错误。

The exception is thrown after execution leaves the Configuration method in startup.cs . 执行在startup.cs离开Configuration方法后抛出异常。 I've registered a Global Exception Handler to try and catch the exception but it is not being caught. 我已经注册了一个全局异常处理程序来尝试捕获异常,但它没有被捕获。

public async override Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)
        {

            var exception = context.Exception;

            const string genericErrorMessage =  "An unexpected error occured";
            var response = context.Request.CreateResponse(HttpStatusCode.InternalServerError,
                new
                {
                    Message = genericErrorMessage
                });

            response.Headers.Add("X - Error & ", genericErrorMessage);
            context.Result = new ResponseMessageResult(response);
        }

config.Services.Replace(typeof(IExceptionHandler), new GlobalExceptionHandler());

the Application_Error method in Global.asax doesn't catch it either Global.asax中的Application_Error方法也没有捕获它

 protected void Application_Error(object sender, EventArgs e)
    {
        HttpContext ctx = HttpContext.Current;
        KeyValuePair<string, object> error = new KeyValuePair<string, object>("ErrorMessage", ctx.Server.GetLastError().ToString());
        ctx.Response.Clear();
    }

I've tried reinstalling the assembly but to no avail. 我已经尝试重新安装程序集但无济于事。

There's two other questions on SO but no solutions 2 的SO问题,但没有解决办法

Despite configuring Visual studio to break on every possible type of exception, this is still not being caught. 尽管将Visual Studio配置为打破每种可能的异常类型,但仍然没有被捕获。 The only place i can tell an exception has occurred is in the output window. 我可以告诉异常的唯一地方是输出窗口。 Nothing is logged to the event logs. 事件日志中没有记录任何内容。

For info this is using VS 2015 有关信息,这是使用VS 2015

SignalR.ReflectedHubDescriptorProvider Warning: 0 : Some of the classes from assembly "Microsoft.AspNet.SignalR.Owin, Version=1.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could Not be loaded when searching for Hubs. SignalR.ReflectedHubDescriptorProvider警告:0:搜索集线器时,无法加载程序集“Microsoft.AspNet.SignalR.Owin,Version = 1.2.2.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”中的某些类。 [...\\Microsoft.AspNet.SignalR.Owin.dll] [... \\ Microsoft.AspNet.SignalR.Owin.dll]

Original exception type: ReflectionTypeLoadException 原始异常类型:ReflectionTypeLoadException

Original exception message: Unable to load one or more of the requested types. 原始异常消息:无法加载一个或多个请求的类型。 Retrieve the LoaderExceptions property for more information. 检索LoaderExceptions属性以获取更多信息。

EDIT: I'm running all the latest Signalr packages 编辑:我正在运行所有最新的信号器包

Installed signalr related packages 已安装的信号器相关包

Autofac.SignalR v 3.0.2 Autofac.SignalR v 3.0.2

Microsoft.AspNet.SignalR v2.2.0 Microsoft.AspNet.SignalR v2.2.0

Microsoft.AspNet.SignalR.Core v2.2.0 Microsoft.AspNet.SignalR.Core v2.2.0

Microsoft.AspNet.SignalR.JS v2.2.0 Microsoft.AspNet.SignalR.JS v2.2.0

Microsoft.AspNet.SignalR.Owin v1.2.2 Microsoft.AspNet.SignalR.Owin v1.2.2

Microsoft.AspNet.SignalR.SelfHost v2.2.0 Microsoft.AspNet.SignalR.SelfHost v2.2.0

Microsoft.AspNet.SignalR.SystemWeb v2.2.0 Microsoft.AspNet.SignalR.SystemWeb v2.2.0

What you are seeing is a log entry create by: ReflectedHubDescriptorProvider 您所看到的是一个由以下内容创建的日志条目: ReflectedHubDescriptorProvider

102 try 
103             { 
104                 return a.GetTypes(); 
105             } 
106             catch (ReflectionTypeLoadException ex) 
107             { 
108                 _trace.TraceWarning("Some of the classes from assembly \"{0}\" could Not be loaded when searching for Hubs. [{1}]\r\n" + 
109                                     "Original exception type: {2}\r\n" + 
110                                     "Original exception message: {3}\r\n", 
111                                     a.FullName, 
112                                     a.Location, 
113                                     ex.GetType().Name, 
114                                     ex.Message); 


116                 return ex.Types.Where(t => t != null); 
117             } 

The exception can be caused by a missing dependency in one of the loaded assemblies, the signalr code is iterating all your assemblies. 异常可能是由于其中一个已加载的程序集中缺少依赖项,信号器代码正在迭代所有程序集。 So the cause can be in any of currently loaded assembles. 因此原因可以是任何当前加载的组件。 Interesting : get-all-types-in-an-assembly and how-to-prevent-reflectiontypeloadexception-when-calling-assembly-gettypes explains the try catch construction used in the ReflectedHubDescriptorProvider. 有趣的是: get-all-types-in-an-assemblyhow-to-prevent-reflectiontypeloadexception-when-calling-assembly-gettypes解释了ReflectedHubDescriptorProvider中使用的try catch构造。 It is just ignoring the classes/hubs it can't load from the Microsoft.AspNet.SignalR.Owin assembly. 它只是忽略了它无法从Microsoft.AspNet.SignalR.Owin程序集加载的类/集线器。

The ReflectionTypeLoadException contains a LoaderExceptions, to access it you can download the source code and add tracing on the ex.LoaderExceptions or add a breakpoint in the sourcecode. ReflectionTypeLoadException包含一个LoaderExceptions,要访问它,您可以下载源代码并在ex.LoaderExceptions上添加跟踪或在源代码中添加断点。

I 'fixed' this problem by creating a new project and copying everything over to the new one/ reinstalling packages again. 我通过创建一个新项目并将所有内容复制到新的/再次重新安装包来解决这个问题。

I no longer get this error, but my Signalr problems have not gone away, so it looks like this one was a red herring. 我不再得到这个错误,但我的信号器问题并没有消失,所以看起来这个是一个红色的鲱鱼。

Glad to hear that you managed to fix assembly loading issue. 很高兴听到您设法解决了装配加载问题。 Here are some tips that might help you get it running! 以下是一些可能有助于您运行的提示!

Enable logging 启用日志记录

To troubleshoot SignalR problems the best thing to do is to enable server & client side logging. 要解决SignalR问题,最好的办法是启用服务器和客户端日志记录。

Client side: 客户端:

$.connection.hub.logging = true;
$.connection.hub.start();

Server side: 服务器端:

var hubConnection = new HubConnection("http://www.contoso.com/");
hubConnection.TraceLevel = TraceLevels.All;
hubConnection.TraceWriter = Console.Out;
IHubProxy stockTickerHubProxy = hubConnection.CreateHubProxy("StockTickerHub");
stockTickerHubProxy.On<Stock>("UpdateStockPrice", stock => Console.WriteLine("Stock update for {0} new price {1}", stock.Symbol, stock.Price));
await hubConnection.Start();

Here are full instructions: 以下是完整说明:

http://www.asp.net/signalr/overview/testing-and-debugging/enabling-signalr-tracing http://www.asp.net/signalr/overview/testing-and-debugging/enabling-signalr-tracing

Check your code and troubleshoot the problem 检查您的代码并解决问题

Here is a list of common mistakes you should check: 以下列出了您应该检查的常见错误:

  • Misspelled method, incorrect method signature, or incorrect hub name; 拼写错误的方法,不正确的方法签名或错误的集线器名称;
  • Duplicate method name on client; 客户端上的方法名称重复;
  • Mixing Hub and PersistentConnection syntax; 混合Hub和PersistentConnection语法;
  • Connection started before subscriptions are added; 在添加订阅之前开始连接;
  • Missing method name on the hub proxy; 集线器代理上缺少方法名称;
  • Hub or hub methods not declared as Public; Hub或hub方法未声明为Public;
  • Manually serializing data; 手动序列化数据;
  • Connection limit reached; 达到连接限制;
  • Cross-domain connection not set up properly; 跨域连接未正确设置;

Here is a full article on how to troubleshoot SignalR issues with code samples: http://www.asp.net/signalr/overview/testing-and-debugging/troubleshooting 以下是有关如何使用代码示例解决SignalR问题的完整文章: http//www.asp.net/signalr/overview/testing-and-debugging/troubleshooting

you have to upgrade my Microsoft.Owin.Security package to 2.1.0 with this command 您必须使用此命令将Mic​​rosoft.Owin.Security包升级到2.1.0

Install-Package Microsoft.Owin.Security -Version 2.1.0 安装包Microsoft.Owin.Security -Version 2.1.0

And modify the bindings in my App.config like this 并修改我的App.config中的绑定

< assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" / > <assemblyIdentity name =“Microsoft.Owin.Security”publicKeyToken =“31bf3856ad364e35”culture =“neutral”/>

< bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" / > <bindingRedirect oldVersion =“0.0.0.0-2.1.0.0”newVersion =“2.1.0.0”/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM