Reverted change to enum parse from string configuration value, as we can't avoid the property being evaluated before the validation has occurred.

This commit is contained in:
Andy Butland
2020-09-21 16:23:58 +02:00
parent 1a59d6a978
commit 574e4d6446
4 changed files with 35 additions and 20 deletions

View File

@@ -17,11 +17,15 @@ namespace Umbraco.Core.Configuration.Models
{
get
{
return Enum.TryParse<LocalTempStorage>(LocalTempStorageLocation, true, out var value)
? value
: throw new InvalidOperationException(
$"Parsing of {nameof(LocalTempStorageLocation)} field value of {LocalTempStorageLocation} was not recognised as a valid value of the enum {nameof(LocalTempStorage)}. " +
$"This state shouldn't have been reached as if the configuration contains an invalid valie it should be caught by {nameof(HostingSettingsValidator)}.");
if (Enum.TryParse<LocalTempStorage>(LocalTempStorageLocation, true, out var value))
{
return value;
}
// We need to return somethhing valid here as this property is evalulated during start-up, and if there's an error
// in the configured value it won't be parsed to the enum.
// At run-time though this default won't be used, as an invalid value will be picked up by HostingSettingsValidator.
return LocalTempStorage.Default;
}
}