Skip to content

[BUG] SuspensionHost extensions broke when nullability was added #2465

@TolikPylypchuk

Description

@TolikPylypchuk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions