You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying out Maui.Markup and saw the docs about C# Hot Reload which I am trying to get working.
I am using the latest VS2022 - 17.13.5
I am using the default project setup for a MAUI application
I have only installed the Maui.Markup package thus far, but was unable to install the latest version as there was a dependency mismatch, so I am using the following:
I implemented the example HotReloadHandler.cs from which the only missing piece was the AppShell.GetRoute() method which I ended up implementing like so:
public partial class AppShell : Shell
{
private static readonly Dictionary<Type, string> _routes = new();
public AppShell()
{
InitializeComponent();
}
static AppShell()
{
// Get all types in the current assembly that are assignable to Page.
var pageTypes = typeof(AppShell).Assembly.GetTypes()
.Where(t => typeof(Page).IsAssignableFrom(t) && !t.IsAbstract);
foreach (var pageType in pageTypes)
{
// Generate a default route based on the type name.
// You can replace this with any convention or custom attribute logic.
var route = pageType.Name.ToLowerInvariant();
// Add the mapping if it doesn't already exist.
if (!_routes.ContainsKey(pageType))
{
_routes.Add(pageType, route);
// Register the route with Shell.
Routing.RegisterRoute(route, pageType);
}
}
}
// This method is called by the Hot Reload handler to resolve a page type to its route.
public static string GetRoute(Type pageType)
{
if (_routes.TryGetValue(pageType, out var route))
{
return route;
}
else
{
// Fallback: if for some reason the type wasn't registered during the static scan,
// create a route using a default naming convention, register it, and return it.
route = pageType.Name.ToLowerInvariant();
_routes[pageType] = route;
Routing.RegisterRoute(route, pageType);
return route;
}
}
}
The issue I am facing is that when I change something in MainPage.cs and hot reload, the app crashes when reaching this part of the HotReloadHandler OnHotReload method
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am trying out Maui.Markup and saw the docs about C# Hot Reload which I am trying to get working.
I am using the latest VS2022 - 17.13.5
I am using the default project setup for a MAUI application
I have only installed the Maui.Markup package thus far, but was unable to install the latest version as there was a dependency mismatch, so I am using the following:
I deleted MainPage.xaml.cs and MainPage.xaml and replaced it with the Maui.Markup example:
I implemented the example HotReloadHandler.cs from which the only missing piece was the AppShell.GetRoute() method which I ended up implementing like so:
The issue I am facing is that when I change something in MainPage.cs and hot reload, the app crashes when reaching this part of the HotReloadHandler OnHotReload method
with debug log
[libc] Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1 in tid 28231 (ame.testmauiapp), pid 28231 (ame.testmauiapp)
Any ideas on what I must do to fix this?
Apologies if I have not provided enough context, this is my first time asking a question like this, and I thank you in advance for any guidance given.
Beta Was this translation helpful? Give feedback.
All reactions