diff --git a/build/Build.bat b/build/Build.bat index 0f1c369bb..513d111e3 100644 --- a/build/Build.bat +++ b/build/Build.bat @@ -8,7 +8,7 @@ ECHO Building ImageProcessor %version%, ImageProcess.Web %webversion% and ImageP ECHO Installing the Microsoft.Bcl.Build package before anything else, otherwise you'd have to run build.cmd twice SET nuGetFolder=%CD%\..\src\packages\ -..\src\.nuget\NuGet.exe install ..\src\ImageProcessor.Web\NET45\packages.config -OutputDirectory %nuGetFolder% +..\src\.nuget\NuGet.exe install ..\src\ImageProcessor.Web\NET4\packages.config -OutputDirectory %nuGetFolder% ECHO Removing _BuildOutput directory so everything is nice and clean RD _BuildOutput /q /s diff --git a/src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs b/src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs index be4966966..89bcf39d7 100644 --- a/src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs +++ b/src/ImageProcessor.Web/NET45/Configuration/ImageProcessorConfiguration.cs @@ -10,18 +10,17 @@ // -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor.Web.Configuration { - #region Using using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Web.Compilation; + + using ImageProcessor.Common.Extensions; using ImageProcessor.Processors; using ImageProcessor.Web.Processors; - #endregion - /// /// Encapsulates methods to allow the retrieval of ImageProcessor settings. /// @@ -301,8 +300,8 @@ namespace ImageProcessor.Web.Configuration // Build a list of native IGraphicsProcessor instances. List availableTypes = BuildManager.GetReferencedAssemblies() .Cast() - .SelectMany(s => s.GetTypes()) - .Where(t => t != null && type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract) + .SelectMany(s => s.GetLoadableTypes()) + .Where(t => type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract) .ToList(); // Create them and add. diff --git a/src/ImageProcessor/Common/Extensions/AssemblyExtensions.cs b/src/ImageProcessor/Common/Extensions/AssemblyExtensions.cs new file mode 100644 index 000000000..763697ef0 --- /dev/null +++ b/src/ImageProcessor/Common/Extensions/AssemblyExtensions.cs @@ -0,0 +1,41 @@ + +namespace ImageProcessor.Common.Extensions +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Reflection; + + /// + /// Encapsulates a series of time saving extension methods to the class. + /// + public static class AssemblyExtensions + { + /// + /// Gets a collection of loadable types from the given assembly. + /// Adapted from + /// + /// + /// The to load the types from. + /// + /// + /// The loadable . + /// + public static IEnumerable GetLoadableTypes(this Assembly assembly) + { + if (assembly == null) + { + throw new ArgumentNullException("assembly"); + } + + try + { + return assembly.GetTypes(); + } + catch (ReflectionTypeLoadException ex) + { + return ex.Types.Where(t => t != null); + } + } + } +} diff --git a/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs b/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs index e1d59b7f6..e6a7f1962 100644 --- a/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs +++ b/src/ImageProcessor/Configuration/ImageProcessorBootstrapper.cs @@ -13,8 +13,8 @@ namespace ImageProcessor.Configuration using System; using System.Collections.Generic; using System.Linq; - using ImageProcessor.Common.Exceptions; + using ImageProcessor.Common.Extensions; using ImageProcessor.Imaging.Formats; /// @@ -65,8 +65,8 @@ namespace ImageProcessor.Configuration Type type = typeof(ISupportedImageFormat); List availableTypes = AppDomain.CurrentDomain .GetAssemblies() - .SelectMany(s => s.GetTypes()) - .Where(t => t != null && type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract) + .SelectMany(s => s.GetLoadableTypes()) + .Where(t => type.IsAssignableFrom(t) && t.IsClass && !t.IsAbstract) .ToList(); this.SupportedImageFormats = availableTypes diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj index 34f818362..4521b06eb 100644 --- a/src/ImageProcessor/ImageProcessor.csproj +++ b/src/ImageProcessor/ImageProcessor.csproj @@ -59,6 +59,7 @@ +