unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.81k stars 708 forks source link

Adjust Hot Reload for iOS/Catalyst/Android #15918

Open jeromelaban opened 6 months ago

jeromelaban commented 6 months ago

What would you like to be added

C# Hot Reload for iOS/Catalyst fails with:

Cannot register two managed types ('unoapp.MainPage#2, unoapp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'unoapp.MainPage#1, unoapp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') with the same native name ('unoapp_MainPage').

While this particular validation does not happen in Android, this fails with iOS/Catalyst.

This particular behavior is handled by the source generator here:

https://github.com/unoplatform/uno/blob/315067c12e3fb077483b5ed94e2bb612f07857b8/src/SourceGenerators/Uno.UI.SourceGenerators/NativeCtor/NativeCtorsGenerator.cs#L165-L166

And to work around it, we'll need to avoid using the CreateNewOnMetadataUpdate and rely on the newest Roslyn to handle lambda captures.

Additional information

The only catch for this feature is MetadataUpdateHanders not being supported yet on VS 2022 for iOS/Android (this, this), and updatedTypes not working on wasm (this), which means we still need a way to detect updated types.

Possibly, we could generate internal CreateNewOnMetadataUpdateAttribute tagged empty types that mirror the original modified types, so that we can determine what was actually changed and raise MetadataUpdateHandlers in Partial Reload.

Update: Android randomly fails for a similar reason, where duplicate types are not handled properly by the runtime.

codesquatch commented 3 months ago

@jeromelabanGiven that https://github.com/dotnet/runtime/issues/93860 has been merged and you've confirmed Hot Reloading is working on that thread, do you have an expected release date for C# Markup Hot Reloading for iOS and Android apps?

jeromelaban commented 3 months ago

@codesquatch Android should work better, though there's a fix that coming in the next release, iOS is still pending this specific issue.

codesquatch commented 3 months ago

@jeromelaban Appreciate the quick response. Unfortunately Hot Reloading is not working for me even on the Android simulator. I'm on Mac OS, VS Code with Uno Platform extension installed and used to build/debug on a Pixel_3a_API_34. I'm using C# Markup instead of XAML for the UI.

jeromelaban commented 3 months ago

Thanks. Note that hot reload on android only works when the debugger is not attached. We're waiting on this issue which should improve the story with the debugger on vscode (even if the issue is about VS windows).