I’m having trouble understanding what I’m doing wrong with the UserError class.
This is the code inside my ViewModel:
this.CheckForUpdateCmd = new ReactiveAsyncCommand(Observable.Return(true));
UserError.RegisterHandler(
uerror =>
{
logger.Error(uerror.ErrorMessage, uerror.InnerException);
if (dlgService.ShowMessageBox(
this,
uerror.ErrorMessage,
ClientStrings.AboutVM_ErrorCheckUpdates,
MessageBoxButton.YesNo,
MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
return Observable.
Return(RecoveryOptionResult.RetryOperation);
}
return Observable.
Return(RecoveryOptionResult.FailOperation);
});
this.
CheckForUpdateCmd.
ThrownExceptions.
SelectMany(ex =>
UserError.Throw(
ClientStrings.AboutVM_ErrorCheckUpdates,
ex)).
Subscribe(
recoverOption =>
{
if (recoverOption == RecoveryOptionResult.RetryOperation)
{
this.CheckForUpdateCmd.Execute(null);
}
});
((ReactiveAsyncCommand)this.CheckForUpdateCmd).
RegisterAsyncAction(_ =>
{
throw new Exception("TESTING 123");
});
After the exception is thrown inside the async action, it is correctly propagated to my Usererror.Throw inside the SelectMany. Inside the Throw method, RxUI throws an ArgumentException with: “You must declare a backing field for this property named: recoveryOptions”
I’ve investigated this and the UserError class has a _RecoveryOptions that is being set from the UserError itself. However, I’m throwing a wrench into the whole process with this inside my App’s OnStartup event handler:
RxApp.GetFieldNameForPropertyNameFunc = prop => prop.Length == 1 ? prop.ToLower() : char.ToLower(prop[0]) + prop.Substring(1);
Basically, I want my backing fields to start with a lower-case letter, not underscore/upper. So far, RxUI has honored this until I tried to use UserError. Am I missing a step or is this a bug in RxUI?
This is for Reactive UI 3.2.0
This is an old bug in ReactiveUI that has been fixed long ago – either upgrade to ReactiveUI 4.x, or copy Errors.cs into your project and use that