Skip to content
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

InvalidArgumentException raised by ExpressionNode in _release_ mode #4011

Closed
vgromfeld opened this issue May 3, 2021 · 5 comments · Fixed by #4014
Closed

InvalidArgumentException raised by ExpressionNode in _release_ mode #4011

vgromfeld opened this issue May 3, 2021 · 5 comments · Fixed by #4014
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior Completed 🔥 hotfix 🌶 priority 🚩
Milestone

Comments

@vgromfeld
Copy link
Contributor

Describe the bug

The animation expression builder is throwing an InvalidArgumentException in release mode when removing all the .Net Native directives from default.rd.xml.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Get the attached sample app
    ExpressionBuiilder.zip
  2. Compile in release
  3. Run the app

Expected behavior

The apps works (as when compiled in debug mode).

Additional context

The generated name for some properties is not valid.
Here is what we get in debug:
image

Here is what we have in release:
image

The issue comes from https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/1e0f17415eae2fd69dc207674b6019ed8656fec2/Microsoft.Toolkit.Uwp.UI.Animations/Expressions/ExpressionNodes/ExpressionNode.cs#L291

Which is not returning a valid string for the composition API. We should remove the : from the returned strings (the .Net Native generated type name when all the reflection code is removed).

Workaround

The current workaround is to force .Net Native to keep all the symbols for Windows.UI.Composition.CompositionPropertySet by using the following Default.rd.xml configuration:

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
  <Application>
    <!-- 
      The animation expression builder is not generating a valid name for the (scalar) parameters coming from the CompositionPropertySet.
      We workaround the issue by forcing the native compiler to keep the reflection information for this type.
    -->
    <Type Name="Windows.UI.Composition.CompositionPropertySet" Dynamic="Public" />
  </Application>
</Directives>
@vgromfeld vgromfeld added the bug 🐛 An unexpected issue that highlights incorrect behavior label May 3, 2021
@ghost ghost added the needs triage 🔍 label May 3, 2021
@ghost
Copy link

ghost commented May 3, 2021

Hello vgromfeld, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

@michael-hawker
Copy link
Member

FYI @Sergio0694

@michael-hawker
Copy link
Member

@vgromfeld since you've identified the code line, did you have a chance to try changing that and seeing if it makes an improvement? Did you want to submit a PR?

@michael-hawker michael-hawker added this to the 7.1 milestone May 4, 2021
@Sergio0694
Copy link
Member

Huh, that's interesting that the missing metadata actually causes such a visible behavioral difference there 🤔
Looks like the fix is straightforward enough thankfully, good find @vgromfeld! 🥳

@michael-hawker
Copy link
Member

It looks like we could replace the magic string with the type with what the Pipeline builder uses to create a unique string:

    // Ensure we have a unique name for each object in our expression.
    string paramName = Guid.NewGuid().ToUppercaseAsciiLetters();

It seems like this reference is pulled up from the hash when needed, so it shouldn't matter what the string is as long as it's unique and confines to the requirements for the Comp APIs.

@Sergio0694 said he's going to optimize that method and move it to a central location for both places to use.

Sergio0694 added a commit to Sergio0694/WindowsCommunityToolkit that referenced this issue May 4, 2021
@ghost ghost added the In-PR 🚀 label May 4, 2021
@ghost ghost closed this as completed in #4014 May 5, 2021
ghost pushed a commit that referenced this issue May 5, 2021
)

## Closes #4011
<!-- 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. -->

## 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. -->
Crash with .NET Native, documented in the related issue.

## What is the new behavior?
<!-- Describe how was this issue resolved or changed? -->
The logic has been changed to not rely on APIs that might have a behavioral change under .NET Native.

## 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)~~
- [X] 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)
- [X] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [X] Contains **NO** breaking changes
@ghost ghost added Completed 🔥 and removed In-PR 🚀 labels May 5, 2021
@michael-hawker michael-hawker modified the milestones: 7.1, 7.0.2 May 11, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jul 11, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior Completed 🔥 hotfix 🌶 priority 🚩
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants