8

I'm getting this error when attempting to load classes in the Microsoft.AspNet.SignalR.Owin assembly.

The exception is thrown after execution leaves the Configurationmethod in startup.cs. 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

 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

Despite configuring Visual studio to break on every possible type of exception, this is still not being caught. 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

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. [...\Microsoft.AspNet.SignalR.Owin.dll]

Original exception type: ReflectionTypeLoadException

Original exception message: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

EDIT: I'm running all the latest Signalr packages

Installed signalr related packages

Autofac.SignalR v 3.0.2

Microsoft.AspNet.SignalR v2.2.0

Microsoft.AspNet.SignalR.Core v2.2.0

Microsoft.AspNet.SignalR.JS v2.2.0

Microsoft.AspNet.SignalR.Owin v1.2.2

Microsoft.AspNet.SignalR.SelfHost v2.2.0

Microsoft.AspNet.SignalR.SystemWeb v2.2.0

Community
  • 1
  • 1
MrBliz
  • 5,830
  • 15
  • 57
  • 81

4 Answers4

7

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.

Community
  • 1
  • 1
Peter
  • 27,590
  • 8
  • 64
  • 84
  • Shouldn't `LoaderExceptions` be included in the Trace itself? I think we can raise this as a bug? – vendettamit Sep 24 '15 at 15:34
  • It would give you some information, however I guess it is ignored because ReflectionTypeLoadException will be thrown in many projects without causing any trouble, the problem class is not used or is not a hub. That is why the exception is only a trace and not rethrown to a higher level. – Peter Sep 24 '15 at 15:42
  • yes, you are right. But there's no harm getting little more info in trace about the exception. – vendettamit Sep 24 '15 at 15:43
  • @peer, yes i'm thinking that this might not even be the cause of the SIgnalR problems i've got, but obviously need to eliminate that possibility. Will download the source tonight and see what i get out of it. – MrBliz Sep 24 '15 at 16:26
  • Created a new project, and no longer get the error, but it seems this problem was not the cause of my signalr issues. – MrBliz Sep 26 '15 at 13:31
5

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.

MrBliz
  • 5,830
  • 15
  • 57
  • 81
4

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

Kaspars Ozols
  • 6,967
  • 1
  • 20
  • 33
  • Thanks for the tips. There's a lot there to go through and this is not something i can do on Work time, so it looks like the bounty will expire before i get a chance to go through all of this. :( – MrBliz Sep 29 '15 at 08:17
  • I've put server side logging in (I already had client side logging on), and the only file that gets created is the transport one. I would have thought that if the server had found a client to broadcast to then it would have created a SignalR-Init log as well? – MrBliz Sep 29 '15 at 19:21
  • Are you sure that your hub is discovered? Is it public? Could you please post some code on how you init SignalR and define hub? – Kaspars Ozols Sep 30 '15 at 07:08
  • 1
    I fixed it. Turned out to be ordering of autofac method calls in startup.cs will post an updated solution later – MrBliz Sep 30 '15 at 07:38
2

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" / >

Manraj
  • 496
  • 2
  • 15