Permalink
Browse files

Use available types from ReflectionTypeLoadException when finding Hubs

- provide better tracing when Assembly.GetTypes() throws

#2712
  • Loading branch information...
1 parent 62d0345 commit e120de01a34681948efb811696b3d3928a360c66 @halter73 halter73 committed Jan 3, 2014
@@ -2,21 +2,28 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
+using Microsoft.AspNet.SignalR.Tracing;
namespace Microsoft.AspNet.SignalR.Hubs
{
public class ReflectedHubDescriptorProvider : IHubDescriptorProvider
{
private readonly Lazy<IDictionary<string, HubDescriptor>> _hubs;
private readonly Lazy<IAssemblyLocator> _locator;
+ private readonly TraceSource _trace;
public ReflectedHubDescriptorProvider(IDependencyResolver resolver)
{
_locator = new Lazy<IAssemblyLocator>(resolver.Resolve<IAssemblyLocator>);
_hubs = new Lazy<IDictionary<string, HubDescriptor>>(BuildHubsCache);
+
+
+ var traceManager = resolver.Resolve<ITraceManager>();
+ _trace = traceManager["SignalR." + typeof(ReflectedHubDescriptorProvider).Name];
}
public IList<HubDescriptor> GetHubs()
@@ -90,14 +97,24 @@ private static bool IsHubType(Type type)
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "If we throw then we have an empty type")]
- private static IEnumerable<Type> GetTypesSafe(Assembly a)
+ private IEnumerable<Type> GetTypesSafe(Assembly a)
{
try
{
return a.GetTypes();
}
- catch
+ catch (ReflectionTypeLoadException ex)
{
+ _trace.TraceWarning(Resources.Warning_ReflectionTypeLoadException, a.FullName, a.Location, ex.Message);
+
+ // Apparently ex.Types can include null elements.
+ // http://msdn.microsoft.com/en-us/library/system.reflection.reflectiontypeloadexception.types(v=vs.110).aspx
+ return ex.Types.Where(t => t != null);
+ }
+ catch (Exception ex)
+ {
+ _trace.TraceWarning(Resources.Warning_GeneralGetTypesException, a.FullName, a.Location, ex.Message);
+
return Enumerable.Empty<Type>();
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -243,4 +243,14 @@
<data name="Forbidden_JSONPDisabled" xml:space="preserve">
<value>Forbidden: JSONP is disabled.</value>
</data>
+ <data name="Warning_GeneralGetTypesException" xml:space="preserve">
+ <value>None of the classes from assembly "{0}" could be loaded when searching for Hubs. [{1}]
+
+{2}</value>
+ </data>
+ <data name="Warning_ReflectionTypeLoadException" xml:space="preserve">
+ <value>Some or all of the classes from assembly "{0}" could not be loaded when searching for Hubs. [{1}]
+
+{2}</value>
+ </data>
</root>

0 comments on commit e120de0

Please sign in to comment.