Skip to content

[HR][Gaps][HD][Navigation] InvalidCastException after HR when navigating via code behind #2903

Open

Description

@Kunal22shah

Current behavior

After adding a call to NavigateViewModelAsync in a ViewModel and triggering HR the following exception is thrown :

System.InvalidCastException: 'Unable to cast object of type 'Chefs.Presentation.LoginModel#1' to type 'Chefs.Presentation.LoginModel'.'

but if I continue HR is successful and navigation also works as expected.

Image

Stack:

System.InvalidCastException
  HResult=0x80004002
  Message=Unable to cast object of type 'Chefs.Presentation.LoginModel#1' to type 'Chefs.Presentation.LoginModel'.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Runtime.CompilerServices.CastHelpers.ChkCast_Helper(Void* toTypeHnd, Object obj)
   at Chefs.Presentation.LoginViewModel.get_Model() in D:\source\uno.chefs\Chefs\obj\Debug\net9.0-desktop\Uno.Extensions.Reactive.Generator\Uno.Extensions.Reactive.Generator.FeedsGenerator\Chefs.Presentation.LoginModel.Bindable.g.cs:line 350
   at Chefs.Presentation.LoginViewModel.get_Login() in D:\source\uno.chefs\Chefs\obj\Debug\net9.0-desktop\Uno.Extensions.Reactive.Generator\Uno.Extensions.Reactive.Generator.FeedsGenerator\Chefs.Presentation.LoginModel.Bindable.g.cs:line 375
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Expected behavior

How to reproduce it (as minimally and precisely as possible)

  1. For a recommended app remove the call await _navigator.NavigateViewModelAsync<SecondModel>(this, data: new Entity(name!)); from the MainModel.
  2. Run the app.
  3. Undo the changes in the VM and trigger HR.

Environment

Nuget Package (s):

Package Version(s):

Affected platform(s):

  • iOS
  • macOS (AppKit)
  • Mac Catalyst
  • Android
  • WebAssembly
  • Windows
  • Skia (WPF)
  • Skia (GTK on Linux/macOS/Windows)
  • Skia (Linux Framebuffer)
  • Build tasks

Visual Studio:

  • 2019 (version: )
  • 2022 (version: )
  • Visual Studio Code (version: )
  • Rider Windows (version: )
  • Rider macOS (version: )

Relevant plugins:

  • Resharper (version: )

Anything else we need to know?

Activity

  1. added
    kind/bug
    triage/untriaged
    on Oct 6, 2025
  2. changed the title [-][HR][Navigation] InvalidCastException after HR[/-] [+][HR][Navigation] InvalidCastException after HR when navigating via code behind[/+] on Oct 6, 2025
  3. added theissue type on Oct 14, 2025
  4. Jen-Uno commented on Oct 29, 2025

    @Jen-Uno
    Contributor

    @Kunal22shah can we have the stack trace, please?

  5. Kunal22shah commented on Oct 29, 2025

    @Kunal22shah
    ContributorAuthor

    @Jen-Uno updated the issue with the stack.

  6. removed
    kind/bug
    triage/untriaged
    on Nov 25, 2025
  7. changed the title [-][HR][Navigation] InvalidCastException after HR when navigating via code behind[/-] [+][HR][HD][gaps] [Navigation] InvalidCastException after HR when navigating via code behind[/+] on Nov 25, 2025
  8. changed the title [-][HR][HD][gaps] [Navigation] InvalidCastException after HR when navigating via code behind[/-] [+][Gaps][HR][HD] [Navigation] InvalidCastException after HR when navigating via code behind[/+] on Nov 25, 2025
  9. changed the title [-][Gaps][HR][HD] [Navigation] InvalidCastException after HR when navigating via code behind[/-] [+][HR][Gaps][HD][Navigation] InvalidCastException after HR when navigating via code behind[/+] on Nov 25, 2025
  10. DevTKSS commented on Dec 5, 2025

    @DevTKSS
    Contributor

    @Kunal22shah I expirience something very similar using x:Bind in the UI Layer with HR. Would you check if this might be the same issue source?

  11. self-assigned this
    on May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions