From 0775d5c085990f0a6aea8b916ece82ec6d352e8d Mon Sep 17 00:00:00 2001 From: Olivier Sasseville Date: Wed, 4 Apr 2018 20:44:51 -0400 Subject: [PATCH] Added a method to find the entrypoint even if some types could not be loaded using reflection. --- RedGate.AppHost.Client/Program.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/RedGate.AppHost.Client/Program.cs b/RedGate.AppHost.Client/Program.cs index 2fb49c1..62c7aeb 100644 --- a/RedGate.AppHost.Client/Program.cs +++ b/RedGate.AppHost.Client/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; @@ -53,9 +54,22 @@ private static IOutOfProcessEntryPoint LoadChildAssembly(string assembly) { var outOfProcAssembly = Assembly.LoadFile(assembly); - var entryPoint = outOfProcAssembly.GetTypes().Single(x => x.GetInterfaces().Contains(typeof (IOutOfProcessEntryPoint))); + Type entryPoint = FindEntryPoint(outOfProcAssembly); - return (IOutOfProcessEntryPoint) Activator.CreateInstance(entryPoint); + return (IOutOfProcessEntryPoint)Activator.CreateInstance(entryPoint); + } + + private static Type FindEntryPoint(Assembly outOfProcAssembly) + { + var types = new Type[]{ }; + try + { + types = outOfProcAssembly.GetTypes(); + } catch (ReflectionTypeLoadException ex) + { + types = ex.Types.Where(x => x != null).ToArray(); + } + return types.Single(x => x.GetInterfaces().Contains(typeof(IOutOfProcessEntryPoint))); } private static void InitializeRemoting(string id, IOutOfProcessEntryPoint entryPoint)