Fix Navigation for Native AOT with Source Generator #1627#2095
Fix Navigation for Native AOT with Source Generator #1627#2095niels9001 merged 7 commits intomicrosoft:mainfrom
Conversation
|
Hi |
|
Thank you for working on this, great job! General question, do we need to include the fully qualified type name? I think for simplicity we can get away with just having the type name itself as key instead of having to prepend "WinUIGallery..." everwhere. |
|
I have a few questions:
|
|
Hello everyone, I apologize for the delay in responding. If you follow the news from Iran, for about the past three weeks, due to protests and unrest, the internet was completely (100%) shut down, and we had no access to anything. As of today, some changes have occurred and a few services, such as GitHub, are accessible again. Things are still not back to normal, and there is always the possibility of reverting to the previous conditions at any moment. Thank you @marcelwgn for review. @Zakariathr22 I don’t have access to the Microsoft sites right now because of the outage that’s going on, but the related documentation still exists and you can find it with a little searching. |
|
Adding to @ghost1372 answers:
As a project that is also oftenly used by people to look for guidance and how to implement things, showing what steps might be necessary to be AOT compatible, I think this project should be AOT compatible. While for bigger apps, the startup performance benefit is bigger, I expect we would still have a small perf benefit (especially for JSON parsing) as well as smaller size foot print. One thing that AOT also enables is assembly trimming so its a double win in that sense.
I think some of the workarounds you see in this PR are also just due to how the code in the gallery is structured. Whenever you do something that does reflection lookups, e.g. finding a type by name, that is something a compiler cannot meaningful know ahead of time. Think about this scenario: What if you modified your local controls.json file to contain a different type name? The compiler wont know what you might write in there so we need to handle these cases. In most apps, having this "lookup a page by a raw string" is not a problem so at least they wont need the work of this app. The same goes for things like the JSON parsing, pretty much as soon as you accept user input, e.g. via a file, you have to specify what things you will accept or not.
Since the AOT we are talking about here is a .Net feature, most of the documentation on this are coming from the .Net side of things. If you are using WinUI 3 with C++, you do not have to think about this matter at all since C++ is already NAOT per definition. |
|
/azp run |
@marcelwgn, thanks for the clarification, at this point I think the app should use C++ at the first place 😄 |
Add a source generator to automatically generate the
NavigationPageMappingsclass, which maps page types to unique IDs. This eliminates the need to use reflection, such asType.GetType(pageString). #1627Before:
After:
NavigationPageMappings.PageDictionary.TryGetValue(item.UniqueId, out Type? pageType);Description
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes