From ea97108e760625ffbf3fc049748b4cd96b970627 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 26 Jan 2014 03:38:24 -0800 Subject: [PATCH] Swallow errors while trying to load types. --- .../DefaultControllerFactory.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs b/src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs index f55cea3a44..35e9d7c0c2 100644 --- a/src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs +++ b/src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs @@ -1,5 +1,7 @@ using System; +using System.Diagnostics; using System.Linq; +using System.Reflection; using Microsoft.AspNet.Abstractions; using Microsoft.AspNet.DependencyInjection; @@ -23,15 +25,26 @@ namespace Microsoft.AspNet.Mvc foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) { - var type = a.GetType(controllerName) ?? - a.GetType(a.GetName().Name + "." + controllerName); + try + { + var type = a.GetType(controllerName) ?? + a.GetType(a.GetName().Name + "." + controllerName); #if NET45 - type = type ?? a.GetTypes().FirstOrDefault(t => t.Name.Equals(controllerName, StringComparison.OrdinalIgnoreCase)); + type = type ?? a.GetTypes().FirstOrDefault(t => t.Name.Equals(controllerName, StringComparison.OrdinalIgnoreCase)); #endif - if (type != null) + if (type != null) + { + return ActivatorUtilities.CreateInstance(_serviceProvider, type); + } + } + catch (ReflectionTypeLoadException) { - return ActivatorUtilities.CreateInstance(_serviceProvider, type); + // TODO: Trace here + } + catch (Exception) + { + // TODO: Trace here } }