-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Microsoft.Toolkit.Uwp.Notifications.dll needs to be included in .NET Native runtime directives #3093
Comments
@andrewleader any thoughts on what may have happened here? |
@michael-hawker no idea, and I'm not aware of or familiar with rd.xml and the new .NET Native runtime directives :/ |
Anything I can do to help with this one? |
@mfeingol there are new changes in the PR #3256, but I don't think they'd be related to this, so not sure if it's worth testing this scenario again with those. But do you happen to know which version you used before where it last worked? Knowing if you have a version of the toolkit and NetCore base NuGet packages that do work would give us a comparison point to see what might have changed since then. @MattWhilden any advice/thoughts here on what might have changed? I'm assuming we may have upgraded the NetCore package, so is there some config change we need to make on our end? |
Unfortunately, I don't, sorry. There was a stretch of maybe 2-3 months before the moment I filed this GHI where the notifications feature wasn't really being used by anyone. I tend to stay current on toolkit updates, so that may provide you with a rough timeline. Best guess is something in the library started using reflection that wasn't before. If it helps, btw, I could put together a small repro project for you. |
@mfeingol a small repo project would be super valuable, especially if we need to get insight from another team about other parts of the platform, makes it easy to hand-off to them without them needing to understand how to build the full toolkit. |
Here you go: https://github.com/mfeingol/repros/tree/master/NotificationsRepro-3093 Note the difference between the toasts when .NET Native is enabled vs disabled. You can enable .NET Native in project build properties on the debug build, or just compare debug vs. release. |
@azchohfi is this something you could take a look at? |
I'll look at this now. |
I could not repro this with v6.0.0 using UniversalWindowsPlatform 6.2.10. A Release build showed the notification exactly the same as a Debug build. |
@azchohfi: I'm still seeing a repro here. Please make sure you're using .NET Native. |
I am using .Net Native. That box is marked by default on Release Builds, but I did double check. |
I'm not sure how to explain the difference then. It's 100% repro here, release or debug, as long as .NET Native is enabled. |
@azchohfi I see the repro on my box (x64, 2004/19041 with VS 2019 16.5.5) when switching from Debug to Release, are you on Insiders? I downgraded the Toolkit NuGet to 5.1.1 and saw the same issue though (as well as our latest 6.1 preview bits): I tried changing the NetCore UWP package, even all the way back to 6.0.1, but saw the same behavior. @MichalStrehovsky & @tommcdon any thoughts on what's going on here? |
I can't seem to repro this either, @mfeingol do you have a full sample you can share on GitHub or somewhere? |
Thank you!! Trying that repro now |
No worries. I just double-checked and the repro is still valid with the latest .NET Native and Toolkit nuget packages. Run it with and without .NET Native and you'll see a difference in how the toast content is displayed. |
Thanks, your repro indeed did repro, but the same code snippet in another project that was targeting SDK 19041 with min ver 17134 worked fine in release .NET native... So still investigating to find the exact conditions that cause the repro just to fully understand scope before applying fix. Thank you so much! |
That's interesting. I just tried my repro project with the following combinations and all seemed to reproduce the problem: 17763 / 18362 => repro |
@andrewleader were you testing against your latest changes (which I assume would have an impact here)? #3622 @mfeingol were you testing against the latest package on NuGet or one of our Preview Packages? |
Nah I was using 6.0.0 to try to repro... still confused with what the difference is but slowly debugging in between other work |
@mfeingol I figured it out! Within Solution Explorer Properties -> Default.rd.xml, your project has the following line commented out <Assembly Name="*Application*" Dynamic="Required All" /> However, when creating a new project today, that line is enabled by default (not commented out). Since Michael also repro'd this, maybe there was a bug in VS where they weren't including this enabled by default? However, new projects seem to be working fine now. Given that things work now with current versions of VS, I'm not sure we should change anything? What do you propose @mfeingol? If we could add something in the nuget package so it works for everyone even if they have that commented out, I'd be open to that, but at least we now know what the problem is! |
@michael-hawker: I was testing with the latest release toolkit package, 6.1.1. @andrewleader: what you observed is accurate. However, most UWP apps need to remove that blanket directive because leaving it in place causes the .NET Native linker to include everything, leading to very large package sizes for non-trivial apps. The workaround is to let the linker do its job by removing the directive, and then manually specifying directives to include specific units of code (assemblies, namespaces, classes) when the linker breaks the app by excluding that code. A trivial example of this would be a class that appears to be unreferenced, but is called from elsewhere via reflection. At runtime, this would result in a MissingMethodException or some such. Now, the maintainers of libraries that behave this way (i.e. break without a linker directive) have two choices: they can fail in these scenarios, leaving it up to app owners to detect and diagnose the issue, or they can do enough homework to put together their own manifest with an appropriately scoped directive. E.g. you may not need to force-include the entire toolkit assembly, just the bits that disappear when linked even when in use. So the ask here for you is to include a manifest in your assembly that makes it unnecessary for people using your library to do all this work. I believe this is documented in https://devblogs.microsoft.com/dotnet/net-native-deep-dive-making-your-library-great/ Does that make sense? |
@andrewleader yeah, I don't remember the setup I had in the repo I did way back. Makes sense though, as I believe that's what @mfeingol pointed to initially. We've typically not done any rd.xml optimizations at the library level for .NET Native in the Toolkit, we've expected app developers to include the default rd.xml settings or optimize themselves for their specific scenarios. We're exploring this a bit more now with #3145, but there'll eventually be a path to .NET 5+ in the future which will work differently, so we're still not trying to micro-optimize. @andrewleader do you know the serialization types that are missing that are getting optimized out for this scenario? If not, it's going to be a bit of a black box I believe. @mfeingol would you expect it to be optimized or if we just included a blanket namespace covering one for the package, would that be sufficient for your case where you've removed the default configuration? As I believe it could still be overridden. (Doc Ref on rd.xml config) @azchohfi @vgromfeld @Sergio0694 any thoughts in this space? |
I think with AOT on the horizon (hopefully?) there's no need to micro-optimize. I recommend applying a blanket workaround for the affected assembly in your own rd.xml:
|
By default, I would favor not doing anything in the toolkit's rd.xml file to not bloat the apps which are not using this specific part of the code. On the other side, with the current split being made to isolate each part of the toolkit in dedicated projects, that could make sense to have one default directive for the |
Sounds like consensus is forming around not making any changes, correct? I'm good with that (my apps personally have just used the default rd.xml personally). And no, I currently don't know the specific serialization types that are getting optimized out. |
I'm not sure I understand the argument for doing nothing. Microsoft.Toolkit.Uwp.Notifications is its own library, and the directive I mentioned above is scoped to it. Apps that don't use notifications won't be linking in Microsoft.Toolkit.Uwp.Notifications anyway, so their apps don't get bigger with the directive in place. Apps that do use notifications will either link everything in, in which case things again don't get worse, or they'll need to debug the problem and add that same directive themselves. So I guess I don't see what the scenario is for the directive making things worse? |
Thanks for pushing back on this! @michael-hawker I submitted a PR, seems like super easy fix (I verified it) and doesn't add any bloat or anything that I'm aware of. Other teams have done the same thing to address this issue: https://github.com/OfficeDev/Open-XML-SDK/pull/241/files |
#3703) <!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 --> <!-- 📝 It is preferred if you keep the "☑️ Allow edits by maintainers" checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork. This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 --> ## Fixes #3093 <!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. --> <!-- Add a brief overview here of the feature/bug & fix. --> Fixing niche case where UWP devs modified their Default.rd.xml causing the library to not work in .NET Native. Thanks to https://github.com/OfficeDev/Open-XML-SDK/pull/241/files used that as reference! ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> - Bugfix <!-- - Feature --> <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> See issue ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> It works! ## PR Checklist Please check if your PR fulfills the following requirements: - [x] Tested code with current [supported SDKs](../readme.md#supported) - [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link --> - [ ] Sample in sample app has been added / updated (for bug fixes / features) - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets) - [ ] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/windows-toolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc... - [x] Tests for the changes have been added (for bug fixes / features) (if applicable) - [ ] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [x] Contains **NO** breaking changes <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. --> ## Other information
Thanks @mfeingol again for filing this issue, we've resolved it with the PR! Apps should now be able to use the notifications toolkit with .NET Native regardless of what they've configured in their own Default.rd.xml :) |
Greatly appreciated, @andrewleader. Thank you. |
Describe the bug
When a UWP app is linked using .NET Native and shipped to the store, toast notifications built using Microsoft.Toolkit.Uwp.Notifications.dll stop working. They still appear, but they lose all context provided by the user and show up as:
The workaround is to include the notifications assembly in rd.xml, like so:
<Assembly Name="Microsoft.Toolkit.Uwp.Notifications" Dynamic="Required All" />
Yes, because this used to work without unnatural acts. But unclear when that was.
Steps to Reproduce
Expected behavior
The Toolkit NuGet package should provide an rd.xml that just works, so apps don't have to figure this out themselves.
cf https://devblogs.microsoft.com/dotnet/net-native-deep-dive-making-your-library-great/
Screenshots
Environment
Package Version(s): 6.0.0
Windows 10 Build Number:
App min and target version:
Device form factor:
Visual Studio
The text was updated successfully, but these errors were encountered: