Reactiveui: [BUG] SuspensionHost extensions broke when nullability was added

Created on 29 Jul 2020  路  2Comments  路  Source: reactiveui/ReactiveUI

Describe the bug

There seem to be 2 issues in the SuspensionHostExtensions class which appeared after upgrading to version 11.5.1. I'll describe them both here since they are quite small. I believe this is because of changes introduced in this commit.

  1. SetupDefaultSuspendResume always throws NullReferenceException. I think this is because this code was added to the method:
if (item.AppState == null)
{
    throw new NullReferenceException(nameof(item.AppState));
}

As far as I understand, item.AppState is always going to be null at this point, because we're just setting up the suspension host and the app state didn't have a chance to be initialized yet.

  1. ObserveAppState always throws InvalidCastException. This is because this line:
return item.WhenAny(x => x.AppState, x => (T)x.Value)

was changed to this:

return item.WhenAny(x => x.AppState, x => (T)x)

So now instead of casting x.Value, it tries to cast x which is of type ObservedChange.

Steps To Reproduce

  1. Try to set up the suspension driver as described in ReactiveUI's docs or in Avalonia's docs.

Expected behavior

Well, I would expect it not to throw any exceptions :)

Environment

  • OS: Windows 10
  • Version: 11.5.1
bug

Most helpful comment

Thanks for confirming. We will have a fix out in a day or so

All 2 comments

I'm having the same problem after updating to 11.5.1.

SetupDefaultSuspendResume throws NullReferenceException on start, and attempting to initialize the AppState to a non-null value before calling SetupDefaultSuspendResume will "workaround" the first bug, but it then throws InvalidCastException, exactly as described by @TolikPylypchuk.

Thanks for confirming. We will have a fix out in a day or so

Was this page helpful?
0 / 5 - 0 ratings