diff --git a/Samples/Stylet.Samples.ModelValidation/FluentModelValidator.cs b/Samples/Stylet.Samples.ModelValidation/FluentModelValidator.cs index 0b61706..8b9b61c 100644 --- a/Samples/Stylet.Samples.ModelValidation/FluentModelValidator.cs +++ b/Samples/Stylet.Samples.ModelValidation/FluentModelValidator.cs @@ -24,13 +24,18 @@ namespace Stylet.Samples.ModelValidation public async Task ValidatePropertyAsync(string propertyName) { - return (await this.validator.ValidateAsync(this.subject, propertyName)).Errors.Select(x => x.ErrorMessage).ToArray(); + // If someone's calling us synchronously, and ValidationAsync does not complete synchronously, + // we'll deadlock unless we continue on another thread. + return (await this.validator.ValidateAsync(this.subject, propertyName).ConfigureAwait(false)) + .Errors.Select(x => x.ErrorMessage).ToArray(); } public async Task> ValidateAllPropertiesAsync() { - return (await this.validator.ValidateAsync(this.subject)).Errors - .GroupBy(x => x.PropertyName) + // If someone's calling us synchronously, and ValidationAsync does not complete synchronously, + // we'll deadlock unless we continue on another thread. + return (await this.validator.ValidateAsync(this.subject).ConfigureAwait(false)) + .Errors.GroupBy(x => x.PropertyName) .ToDictionary(x => x.Key, x => x.Select(failure => failure.ErrorMessage).ToArray()); } } diff --git a/Samples/Stylet.Samples.ModelValidation/Pages/UserView.xaml b/Samples/Stylet.Samples.ModelValidation/Pages/UserView.xaml index 6dbd6c7..4785f06 100644 --- a/Samples/Stylet.Samples.ModelValidation/Pages/UserView.xaml +++ b/Samples/Stylet.Samples.ModelValidation/Pages/UserView.xaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:s="https://github.com/canton7/Stylet" + xmlns:xaml="clr-namespace:Stylet.Samples.ModelValidation.Xaml" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> @@ -11,7 +12,7 @@ - +