diff --git a/Src/FluentAssertions/Common/ConfigurationStoreExceptionInterceptor.cs b/Src/FluentAssertions/Common/ConfigurationStoreExceptionInterceptor.cs new file mode 100644 index 0000000000..fe06927a06 --- /dev/null +++ b/Src/FluentAssertions/Common/ConfigurationStoreExceptionInterceptor.cs @@ -0,0 +1,36 @@ +#if !NETSTANDARD1_3 && !NETSTANDARD1_6 + +namespace FluentAssertions.Common +{ + internal class ConfigurationStoreExceptionInterceptor : IConfigurationStore + { + private bool underlyingStoreUnavailable; + + private readonly IConfigurationStore configurationStore; + + public ConfigurationStoreExceptionInterceptor(IConfigurationStore configurationStore) + { + this.configurationStore = configurationStore; + } + + public string GetSetting(string name) + { + if (underlyingStoreUnavailable) + { + return null; + } + + try + { + return configurationStore.GetSetting(name); + } + catch + { + underlyingStoreUnavailable = true; + return null; + } + } + } +} + +#endif diff --git a/Src/FluentAssertions/Common/Services.cs b/Src/FluentAssertions/Common/Services.cs index cfc2f745dc..43351e1dec 100644 --- a/Src/FluentAssertions/Common/Services.cs +++ b/Src/FluentAssertions/Common/Services.cs @@ -48,7 +48,7 @@ public static void ResetToDefaults() ConfigurationStore = new NullConfigurationStore(); #else Reflector = new FullFrameworkReflector(); - ConfigurationStore = new AppSettingsConfigurationStore(); + ConfigurationStore = new ConfigurationStoreExceptionInterceptor(new AppSettingsConfigurationStore()); #endif ThrowException = TestFrameworkProvider.Throw;