diff --git a/NzbDrone.Api/ClientSchema/SchemaBuilder.cs b/NzbDrone.Api/ClientSchema/SchemaBuilder.cs index 1393387bc..c5c96c302 100644 --- a/NzbDrone.Api/ClientSchema/SchemaBuilder.cs +++ b/NzbDrone.Api/ClientSchema/SchemaBuilder.cs @@ -57,6 +57,8 @@ namespace NzbDrone.Api.ClientSchema public static object ReadFormSchema(List fields, Type targetType) { + Ensure.That(() => targetType).IsNotNull(); + var properties = targetType.GetSimpleProperties(); var target = Activator.CreateInstance(targetType); diff --git a/NzbDrone.Common/Reflection/ReflectionExtensions.cs b/NzbDrone.Common/Reflection/ReflectionExtensions.cs index 0c70d0c42..898d45119 100644 --- a/NzbDrone.Common/Reflection/ReflectionExtensions.cs +++ b/NzbDrone.Common/Reflection/ReflectionExtensions.cs @@ -62,7 +62,7 @@ namespace NzbDrone.Common.Reflection public static Type FindTypeByName(this Assembly assembly, string name) { - return assembly.GetTypes().Single(c => c.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)); + return assembly.GetTypes().SingleOrDefault(c => c.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)); } public static bool HasAttribute(this Type type) diff --git a/NzbDrone.Core.Test/IndexerTests/IndexerServiceFixture.cs b/NzbDrone.Core.Test/IndexerTests/IndexerServiceFixture.cs index 2012921f0..bbfb8404a 100644 --- a/NzbDrone.Core.Test/IndexerTests/IndexerServiceFixture.cs +++ b/NzbDrone.Core.Test/IndexerTests/IndexerServiceFixture.cs @@ -71,6 +71,7 @@ namespace NzbDrone.Core.Test.IndexerTests var existingIndexers = Builder.CreateNew().BuildNew(); + existingIndexers.ConfigContract = typeof (NewznabSettings).Name; repo.Insert(existingIndexers); diff --git a/NzbDrone.Core/Datastore/Converters/ProviderSettingConverter.cs b/NzbDrone.Core/Datastore/Converters/ProviderSettingConverter.cs index 8e83938a9..ace64d6af 100644 --- a/NzbDrone.Core/Datastore/Converters/ProviderSettingConverter.cs +++ b/NzbDrone.Core/Datastore/Converters/ProviderSettingConverter.cs @@ -23,11 +23,15 @@ namespace NzbDrone.Core.Datastore.Converters } var ordinal = context.DataRecord.GetOrdinal("ConfigContract"); + var contract = context.DataRecord.GetString(ordinal); - var implementation = context.DataRecord.GetString(ordinal); + var impType = typeof (IProviderConfig).Assembly.FindTypeByName(contract); - var impType = typeof (IProviderConfig).Assembly.FindTypeByName(implementation); + if (impType == null) + { + throw new ConfigContractNotFoundException(contract); + } return Json.Deserialize(stringValue, impType); } diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index e5058b047..582096964 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -414,6 +414,7 @@ + diff --git a/NzbDrone.Core/ThingiProvider/ConfigContractNotFoundException.cs b/NzbDrone.Core/ThingiProvider/ConfigContractNotFoundException.cs new file mode 100644 index 000000000..47d6ecdf3 --- /dev/null +++ b/NzbDrone.Core/ThingiProvider/ConfigContractNotFoundException.cs @@ -0,0 +1,13 @@ +using NzbDrone.Common.Exceptions; + +namespace NzbDrone.Core.ThingiProvider +{ + public class ConfigContractNotFoundException : NzbDroneException + { + public ConfigContractNotFoundException(string contract) + : base("Couldn't find config contract " + contract) + { + } + + } +} diff --git a/NzbDrone.Core/ThingiProvider/ProviderService.cs b/NzbDrone.Core/ThingiProvider/ProviderService.cs index 9869f9679..4765de4bc 100644 --- a/NzbDrone.Core/ThingiProvider/ProviderService.cs +++ b/NzbDrone.Core/ThingiProvider/ProviderService.cs @@ -48,7 +48,7 @@ namespace NzbDrone.Core.ThingiProvider { ConfigContract = p.ConfigContract.Name, Implementation = p.GetType().Name, - Settings = (IProviderConfig)Activator.CreateInstance(ReflectionExtensions.CoreAssembly.FindTypeByName(p.ConfigContract.Name)) + Settings = (IProviderConfig)Activator.CreateInstance(p.ConfigContract) }).ToList(); }