# HG changeset patch # User Steven Robbins # Date 1295559852 0 # Node ID 05b519958f290c79c8c68284366d7f9de275f86c # Parent 9569cf22edf5be9380102435107ed7c6694c451f Added an extension method to try and handle assembly loading errors when calling GetTypes. diff -r 9569cf22edf5be9380102435107ed7c6694c451f -r 05b519958f290c79c8c68284366d7f9de275f86c src/TinyIoC/TinyIoC.cs --- a/src/TinyIoC/TinyIoC.cs Mon Jan 17 07:02:31 2011 +0000 +++ b/src/TinyIoC/TinyIoC.cs Thu Jan 20 21:44:12 2011 +0000 @@ -137,6 +137,29 @@ #endregion #region Extensions + public static class AssemblyExtensions + { + public static Type[] SafeGetTypes(this Assembly assembly) + { + Type[] assemblies; + + try + { + assemblies = assembly.GetTypes(); + } + catch (System.IO.FileNotFoundException) + { + assemblies = new Type[] { }; + } + catch (System.NotSupportedException) + { + assemblies = new Type[] { }; + } + + return assemblies; + } + } + public static class TypeExtensions { /// @@ -2531,7 +2554,7 @@ { var defaultFactoryMethod = this.GetType().GetMethod("GetDefaultObjectFactory", BindingFlags.NonPublic | BindingFlags.Instance); - var types = assemblies.SelectMany(a => a.GetTypes()).Where(t => !IsIgnoredType(t)).ToList(); + var types = assemblies.SelectMany(a => a.SafeGetTypes()).Where(t => !IsIgnoredType(t)).ToList(); var concreteTypes = from type in types where (type.IsClass == true) && (type.IsAbstract == false) && (type != this.GetType() && (type.DeclaringType != this.GetType()) && (!type.IsGenericTypeDefinition))