Signalr assembly loading issue OWIN

荒凉一梦 提交于 2019-12-05 03:22:16
Peter

What you are seeing is a log entry create by: 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. It is just ignoring the classes/hubs it can't load from the Microsoft.AspNet.SignalR.Owin assembly.

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.

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.

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

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;
  • Connection started before subscriptions are added;
  • Missing method name on the hub proxy;
  • Hub or hub methods not declared as 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

you have to upgrade my Microsoft.Owin.Security package to 2.1.0 with this command

Install-Package Microsoft.Owin.Security -Version 2.1.0

And modify the bindings in my App.config like this

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!