Skip to content

[HotReload][Mvux] Changing Model>State Name results in HotReloadException #86

Closed
unoplatform/uno.extensions
#2830

Description

@DevTKSS

Current behavior

Image

Expected behavior

just reload and update as normal...

Which tool(s) are affected?

Hot Reload

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

changes done:

<Page x:Class="DevTKSS.Uno.Samples.MvuxGallery.Presentation.Views.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:DevTKSS.Uno.Samples.MvuxGallery.Presentation.Views"
      xmlns:uen="using:Uno.Extensions.Navigation.UI"
      xmlns:utu="using:Uno.Toolkit.UI"
      xmlns:um="using:Uno.Material"
      xmlns:ctk="using:CommunityToolkit.WinUI.Converters"
      uen:Region.Name="Main"
      NavigationCacheMode="Required"
      Background="{ThemeResource BackgroundBrush}">

    <Page.Resources>
        <ctk:BoolNegationConverter x:Name="InvertBoolConv"/>
    </Page.Resources>
    <Grid x:Name="MainContentGrid"
          uen:Region.Attached="True">
-      <Grid.RowDefinitions>
-            <RowDefinition Height="Auto" />
-           <RowDefinition Height="Auto"/>
-           <RowDefinition Height="Auto" />
-           <RowDefinition Height="*" />
-       </Grid.RowDefinitions>
-      <Grid.ColumnDefinitions>
-          <ColumnDefinition Width="*" />
-          <ColumnDefinition Width="*" />
-      </Grid.ColumnDefinitions>
-       <utu:NavigationBar x:Name="NavBar"
-                         Grid.Row="0"
-                         Grid.ColumnSpan="2"
-                         HorizontalAlignment="Stretch"
-                         HorizontalContentAlignment="Center"
-                         VerticalContentAlignment="Center"
-                         VerticalAlignment="Top"
-                          Content="{Binding Path=AppTitle, Mode=OneWay}"
-                          MainCommandMode="Action"
-                          Background="{ThemeResource PrimaryContainerBrush}"
-                          Foreground="{ThemeResource OnPrimaryContainerBrush}">
-           <utu:NavigationBar.MainCommand>
-               <AppBarButton Icon="GlobalNavigationButton"
-                            Command="{x:Bind NavView.IsPaneOpen, Converter={StaticResource InvertBoolConv}}"
-                            Width="{x:Bind NavView.CompactPaneLength, Mode=OneWay}"
-                            HorizontalContentAlignment="Center"/>
-          </utu:NavigationBar.MainCommand>
-       </utu:NavigationBar>

-       <TextBlock Grid.Row="1"
-                  Grid.Column="0"
-                   HorizontalTextAlignment="Right"
-                  Text="Notifier Region:" />
-        <TextBlock Grid.Row="1" Grid.Column="1"
-                   Text="{Binding Path=CurrentNotifierRegion, Mode=OneWay}" />
-        <TextBlock Grid.Row="2"
-                   Grid.Column="0"
-                   HorizontalTextAlignment="Right"
-                   Text="Notifier Route:" />
-       <TextBlock Grid.Row="2" Grid.Column="1"
-                  Text="{Binding Path=CurrentNotifierRoute, Mode=OneWay}" />
        
        <NavigationView  x:Name="NavView"
-                        IsBackButtonVisible="Collapsed"
+                       IsBackButtonVisible="Auto"
                         IsPaneToggleButtonVisible="False"
+                         IsTitleBarAutoPaddingEnabled="False"
-                       Grid.Row="3" Grid.ColumnSpan="2"
+                     Header="{Binding Greeting, Mode=OneWay}"
-                       PaneDisplayMode="LeftCompact"
+                      PaneDisplayMode="Auto"
                         uen:Region.Attached="True"
                         HorizontalAlignment="Stretch">
            <NavigationView.MenuItems>
                <NavigationViewItem x:Name="NavItemDashboard"
                                    Content="Home"
                                    uen:Region.Name="Dashboard"
                                    Icon="Home" />
                <NavigationViewItem x:Name="NavItemCounter"
                                    Content="Counter"
                                    Icon="Calculator"
                                    uen:Region.Name="Counter" />

                <NavigationViewItem  Content="List View"
                                     uen:Region.Name="Listboard"
                                     Icon="List" />
                <NavigationViewItem Content="Let's play Cards!"
                                    uen:Region.Name="SimpleCards"
                                    Icon="Page" />
            </NavigationView.MenuItems>

            <NavigationView.Content>
                <Grid x:Name="NavigationViewContentGrid"
                      uen:Region.Attached="True"
                      uen:Region.Navigator="Visibility"
                      Visibility="Visible"/>
            </NavigationView.Content>
        </NavigationView>

    </Grid>

</Page>

Model:

namespace DevTKSS.Uno.Samples.MvuxGallery.Presentation.ViewModels;
public partial record MainModel
{
    private readonly INavigator _navigator;
    private readonly ILocalizationService _localizationService;
    private readonly IStringLocalizer _stringLocalizer;
    private readonly IRouteNotifier _routeNotifier;
    public MainModel(
        ILocalizationService localizationService,
        IStringLocalizer stringLocalizer,
        INavigator navigator,
        IRouteNotifier routeNotifier)
    {
        _routeNotifier = routeNotifier;
        _navigator = navigator;
        _localizationService = localizationService;
        _stringLocalizer = stringLocalizer;
        _routeNotifier.RouteChanged += (s,routeArgs) =>
        {
            this.CurrentNotifierRoute.SetAsync(routeArgs.Navigator?.Route?.ToString() ?? string.Empty); // actual current nested route
            this.CurrentNotifyerRegion.SetAsync(routeArgs.Region?.Name?.ToString()); // no return from this
        };
    }
-     public IState<string> AppTitle => State<string>.Value(this, () => _stringLocalizer["ApplicationName"]);
+    public IState<string> Greeting => State<string>.Value(this, () => _stringLocalizer["ApplicationName"]);
    public IState<string> CurrentNotifyerRegion => State<string>.Value(this, () => _navigator.Route?.ToString() ?? string.Empty);
    public IState<string> CurrentNotifierRoute => State<string>.Value(this,() => string.Empty);
}

Workaround

Restart App instead HotReload

Renderer

  • Skia
  • Native

Affected platforms

No response

Uno.Sdk version

6.0.67

IDE used

Visual Studio 2022

IDE version

17.13.6

Uno Platform Extension version

6.0.30.30

Relevant plugins

No response

Anything else we need to know?

Used Right mouse button click >"Rename" command in vs 2022 to rename "AppTitle" to "Greetings"

Activity

  1. added
    triage/untriaged
    on May 15, 2025
  2. agneszitte commented on May 21, 2025

    @agneszitte
    Member

    @dr1rrb, @kazo0 I will let you take a look at the details for this issue

  3. dr1rrb commented on Jun 16, 2025

    @dr1rrb
    Member

    @DevTKSS hey, I'm indeed able to see such exception.

    It's because when a MVUX Model is being updated, we raise a PropertyChanged("") (on the ViewModel) to update all bindings. But in you case the binding to AppTitle is no longer valid, causing the exception to be thrown. It will be removed in coming UI update, but we don't have real control on timing here so the update from MVUX might pass before the UI is being updated.

    However, the exception is catched (https://github.com/unoplatform/uno/blob/master/src/Uno.UI/DataBinding/BindingPath.BindingItem.cs#L301) and should not cause any other issue.

    Does the exception was crashing your application? Did you experience any kind of problem after the update, or you opened the issue just to report that the exception was thrown ? (If so, you can mute them by enabling "Just My Code" in debugger options).

  4. DevTKSS commented on Jun 16, 2025

    @DevTKSS
    Author

    @dr1rrb yes, everytime I am doing this as you better worded out, my app does crash and I have no other option than to Re-Start instead of HotReload it :( so it would be great if there is any chance to be able to reload instead of restart then in the future

  5. dr1rrb commented on Jun 18, 2025

    @dr1rrb
    Member

    Ok I investigated a bit more, the only case I was able to find that is not working with HR, is to "add" (rename == remove + add) a new Feed then updating that feed in a second HR operation will not work (Note: it's not related to the HotReloadException itself, more probably just an issue with reflection discovery of feeds).

    Does this correspond to your case? If not, are you able to give me more details (repro steps / repro app) ?

    BTW by "crash the app" I was meaning the app closes. What I understand from "I have no other option than to Re-Start instead of HotReload it" is that it's not the case? It's really about the hot-reload not behaving as expected after the rename?

  6. DevTKSS commented on Jun 18, 2025

    @DevTKSS
    Author

    @dr1rrb hm I dont know if this is possible, but from my POV, this here and unoplatform/uno#20438
    is talking about the same issue and should get merged to one. I just remembered, that I did send some exception output and mentioned it maybe not just here, so researched also in my "mentioned" notifications to find it.
    Would you check on that additional context if that might helps you?

    to the crash app:
    I am meaning that I runned normally in debug mode, did some modifications, like the renaming of the State Properties in my Model and modified the code in my page as showed in the diff, then I wanted to normally Reload the app, because I am not able to modify the names of properties from the HD GUI, therefore I switched into HotReload to do this, meant to HotReload to then enter again the HD mode and 💥exception showed above. then I was not able to go back into HR/HD mode because it did not let me. It required me to Re-Start the app as without HR

  7. DevTKSS commented on Jun 18, 2025

    @DevTKSS
    Author

    and this here included the State thing also partially:
    #35 (comment)

  8. dr1rrb commented on Jun 18, 2025

    @dr1rrb
    Member

    Ok thanks for the details @DevTKSS 👍If you got both exception during the same debug session, this confirms that the HRException is actually not the root cause of your issues, but the unoplatform/uno#20438.

    Working to get the MVUX HR issue fixed, still problematic that a freshly added feed cannot be edited.

    BTW For the unoplatform/uno#20438 it's one of the next tasks on my plate. It is actually a bug in roslyn that we have already workaround few times ... hopefully we will be able to do so also for your case (we are supposed to have a bug open for that on roslyn's side).

  9. DevTKSS commented on Jun 19, 2025

    @DevTKSS
    Author

    @dr1rrb I am not sure if it was the exact same session and I don't see their differences (missing knowledge)
    but if happening its always caused when I am changing the statefull props on the model and reasonable you would when renaming them, change also the binding setup accordingly.
    What I did not try so far, as I did not understand that to be exactly recommended from uno docs, to put the model code in a seperate project, to workaround the Roslyn generator problem.

  10. removed
    triage/untriaged
    on Jun 19, 2025
  11. added theissue type on Jun 22, 2025
  12. dr1rrb commented on Jul 7, 2025

    @dr1rrb
    Member

    QA steps:

    1. Create a new recommended app (using MVUX)
    2. Start the app
    3. Go into MainModel.cs and rename the IState<string> Name to something like MySuperName
    4. In the MainPage.xaml update the binding of TextBlock on line 22 to match the new name <TextBox Text="{Binding MySuperName, Mode=TwoWay}"
    5. Save all files and invoke HR
    6. In the MainModel change the content of the MySuperName state from State<string>.Value(this, () => string.Empty); to State<string>.Value(this, () => "This is my super app");
    7. Save and invoke HR
    8. ==> Observe that the name is being updated in app
    9. Rename back to Name (both in MainModel.cs and MainPage.xaml) and also change again the content to the state to something like State<string>.Value(this, () => "This is the name of my app");
    10. ==> Observe that the name is being updated in app
  13. self-assigned this
    on Jul 7, 2025
  14. Darsh0307 commented on Jul 7, 2025

    @Darsh0307

    @dr1rrb

    I am still getting the exception errors. In the step 5 as soon as i save after that i am getting the exception error. I think so that it has the same exception error as mentioned above.

    uno.sdk:- 6.1.8
    OS:- Window
    IDE:- VS
    VS:-Version 17.14.5

    Exception

    $exception {"Attempted to invoke a deleted method implementation. This can happen when a method is deleted or its name or signature is changed while the application is running."} System.Runtime.CompilerServices.HotReloadException

    Message

    Attempted to invoke a deleted method implementation. This can happen when a method is deleted or its name or signature is changed while the application is running.

    Detials

    System.Runtime.CompilerServices.HotReloadException
      HResult=0x80131500
      Message=Attempted to invoke a deleted method implementation. This can happen when a method is deleted or its name or signature is changed while the application is running.
      Source=bn
      StackTrace:
       at bn.Presentation.MainViewModel.get_Name()
    
    
    Screen.Recording.2025-07-07.at.4.59.39.PM.mov
    Screen.Recording.2025-07-07.at.4.52.15.PM.mov
  15. dr1rrb commented on Jul 7, 2025

    @dr1rrb
    Member

    @Darsh0307 please don't stop to the exception (we cannot avoid it), press the "Continue" button (or F5) in order to validate if the behavior / HR is still correct.

  16. Darsh0307 commented on Jul 8, 2025

    @Darsh0307

    @dr1rrb

    After pressing continue button i was able to validate the changes which we were able to make.

    uno.sdk:- 6.1.8
    OS:- Window
    IDE:- VS
    VS:-Version 17.14.5

    Screen.Recording.2025-07-08.at.10.37.59.AM.mov
  17. DevTKSS commented on Jul 14, 2025

    @DevTKSS
    Author

    @dr1rrb some new feed for you to check on, getting the same error, unrecoverable, no state usage, only x:Name and x:Bind (try) to another control:

    https://technischekonstruktion-my.sharepoint.com/:v:/g/personal/info_technische-konstruktion_com/ET9YfAXjdXlJq7If3ezAWBwBhThK1VGvu9kK4hFQpwBx9Q?e=hR7AZV

    I were trying to use HD for somehow bind the click on tabBar>TabBarItem or SelectedItem 🤷 to expand the expander if not expanded, so the user would not have to do a second click.
    But as soon as I rename using x:Name like shown in the linked video (Github didnt want to allow me to drop it, sorry) it will do one of those behaviours:

    1. Infinity loop of "updating" if I rename the TabBar
    2. if 1 does not happen, the trying to define an x:Bind is making it break, no "continue" as you mentioned above does solve it.

    used latest available stable release 6.0.146

    will now use the SelectionChanged Event (not available on HD) with the following code in the page codebehind:

        public DashboardPage()
        {
            this.InitializeComponent();
            this.CodeSampleTabBar.SelectionChanged += (s, e) =>
            {
                if (this.CodeSampleTabBar.SelectedIndex > -1)
                {
                    this.CodeSampleExpander.IsExpanded = true;
                }
            };
        }

    but as those things are kind of... basics, it would be good, to not break HD with those things maybe?

  18. dr1rrb commented on Jul 18, 2025

    @dr1rrb
    Member

    @DevTKSS

    It happens that an exception is being re-thrown or more than one exception is thrown, that's why you might have to press more than once the "continue" button. You can repeatedly press it until the application resume, or (recommended) you on the first exception you can uncheck this box (and then press "Continue" (F5) -or "Weiter" in your case ;) - )

    Image

    To give more details: That exception is being injected by the hot-reload engine to replace body of methods that has been removed, so if you try to invoke such stale method it just throws that exception. When updating (actually "replacing") the visual tree, there are lot of things that happens in parallel and it might happen that a removed method is being invoked (common case are event handlers and x:Bind, for instance a Unload handler pointing to a such stale method).
    While this exception is usefull to avoid invalid state, there is no real benefit to break on it, so ignoring it is really the recommended option here.

  19. DevTKSS commented on Jul 18, 2025

    @DevTKSS
    Author

    @dr1rrb oh okay so can I "ignore" all of the HotReloadException" throws or are there just particular "error codes" like a "hde1234" or similar?
    I don't know much about how or better where to define fir the IDE to ignore on exceptions🤔 but sibce we have those checkboxes in the screenshot I would guess, there are some settings that would be usable?
    Would you know if we could somehow get this set in... directory.Build.props for example where we having the error code linting settings already in our solution? Or alternatively I did recognize lately on an aspire template, that it seems to be able to ignore error codes by defining the ignore codes on the PackageReference 💡

  20. dr1rrb commented on Aug 1, 2025

    @dr1rrb
    Member

    As far as I know, this is not something you can configure in the Directory.Build.props nor the .editoconfig files, it's really a Visual Studio specific configuration (and anyway on my side I'm toggling those on and off multiple times a day, would not want this to be stored in a file on the repo).

    You can see the full list of known exceptions in Debug > Windows > Exception Settings (Ctrl + Alt + E) and then use checkboxes to enable / disable the "break on throw" of exceptions in the "Common Language Runtime Exceptions" section . You can also right-click and select Restore Defaults to select only "known to be meaning full" exceptions:

    Image
  21. jhanvi03 commented on Aug 12, 2025

    @jhanvi03

    Marking as QA Review Done — the original issue has been addressed, and clicking 'Continue' allows changes to apply despite the HotReloadException behavior explained above.

    Screen.Recording.2025-08-12.at.12.09.43.AM.mov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions