From 76faf89acaad295bddc2dfc5428fa6052931f89d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 2 Oct 2013 12:20:11 -0400 Subject: handle type creation errors --- .../BaseApplicationHost.cs | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'MediaBrowser.Common.Implementations/BaseApplicationHost.cs') diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index fe0abcae0..4c2d5d599 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -159,7 +159,7 @@ namespace MediaBrowser.Common.Implementations protected IZipClient ZipClient { get; set; } protected IIsoManager IsoManager { get; set; } - + /// /// Initializes a new instance of the class. /// @@ -243,7 +243,7 @@ namespace MediaBrowser.Common.Implementations /// Runs the startup tasks. /// /// Task. - public virtual Task RunStartupTasks() + public virtual Task RunStartupTasks() { return Task.Run(() => { @@ -384,7 +384,7 @@ namespace MediaBrowser.Common.Implementations /// /// The type. /// System.Object. - public object CreateInstance(Type type) + protected object CreateInstance(Type type) { try { @@ -398,6 +398,25 @@ namespace MediaBrowser.Common.Implementations } } + /// + /// Creates the instance safe. + /// + /// The type. + /// System.Object. + protected object CreateInstanceSafe(Type type) + { + try + { + return Container.GetInstance(type); + } + catch (Exception ex) + { + Logger.Error("Error creating {0}", ex, type.Name); + + return null; + } + } + /// /// Registers the specified obj. /// @@ -496,7 +515,11 @@ namespace MediaBrowser.Common.Implementations /// IEnumerable{``0}. public IEnumerable GetExports(bool manageLiftime = true) { - var parts = GetExportTypes().Select(CreateInstance).Cast().ToList(); + var parts = GetExportTypes() + .Select(CreateInstanceSafe) + .Where(i => i != null) + .Cast() + .ToList(); if (manageLiftime) { -- cgit v1.2.3