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

Possible bug in [RelayCommand] async task #356

Open
Sergio0694 opened this issue Jul 26, 2022 Discussed in #355 · 3 comments
Open

Possible bug in [RelayCommand] async task #356

Sergio0694 opened this issue Jul 26, 2022 Discussed in #355 · 3 comments
Labels
mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit needs author feedback 📝 This issue or PR needs a reply from the author unverified ⌛ Needs more investigation to conclude it's an actual bug

Comments

@Sergio0694
Copy link
Member

Discussed in #355

Originally posted by DarthMazut July 26, 2022
Hello,
when I mark my command with [RelayCommand] and use async Task signature then when synchronouse part of code throws exception this exception is swallow and another criptic exception is thrown instead. Let me give you an excample:

In my view I bind Button's command to my VM command, like so:

<Button Command="{Binding CommandCommand}">Click Me</Button>

In my VM I do the following:

[RelayCommand]
 private async Task Command()
 {
      throw new NotImplementedException();
      await Task.Delay(100);
 }

this simulates any method that has some async call, but before awaiting it, an exception has been thrown by prior part of code.
In such case, after pressing button I receive:
Unhandled exception at 0x76B757B1 (combase.dll) in TestApp1.exe: 0xC000027B: Wystąpił wewnętrzny wyjątek aplikacji (parameters: 0x16B993B0, 0x00000001). and eventually this:
Exception thrown at 0x00DBE538 in TestApp1.exe: 0xC0000005: Access violation executing location 0x00DBE538.

This happens only when my method signature is async Task, when changing it to async void the proper exception is thrown.
My question is whether this is expected or it's a bug? Should I use async void? I though async Task is recommended?

This is obviously problematic because if I throw meaningfull exception from my code I'd like to see those instead of this Access violation internal stuff.

@Sergio0694 Sergio0694 added bug 🐛 An unexpected issue that highlights incorrect behavior needs author feedback 📝 This issue or PR needs a reply from the author mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit labels Jul 26, 2022
@Sergio0694
Copy link
Member Author

@DarthMazut This is weird, and I'm not sure I see how such an exception could be caused by the MVVM Toolkit.
Do you have a minimal repro? Is this on WinUI 3, by any chance? If so, what version of it?

@DarthMazut
Copy link

DarthMazut commented Jul 28, 2022

Yes, I'm using WinUI 3. This happens in both of my projects, including the test one (which has only 1 Page + 1 VM)
My setup is:
Original project
Application assembly

<PackageReference Include="CommunityToolkit.WinUI.UI" Version="7.1.2" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.3" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.1" />

ViewModels assembly

<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview4" />

Test project (to make sure it's not something specific to my code)

<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview4" />
 <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.3" />
 <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25163-preview" />

Repro steps for me is:

  1. Create new WinUI Blank App, Packaged project
  2. Install CommunityToolkit.Mvvm
  3. Create VM that implements ObservableObject
  4. Mark async Task method with [RelayCommand] atribute, throw inside
  5. In View setup DataContext to created VM, bind command to button
  6. Run app (Package), click button, see strange exception

@Sergio0694
Copy link
Member Author

I suspect this is related to microsoft/microsoft-ui-xaml#5221. @DarthMazut could you update the WASDK version you're using to Microsoft.WindowsAppSDK.1.2.221209.1 (or greater) and see if you can still repro?
Thank you! 🙂

@Sergio0694 Sergio0694 added unverified ⌛ Needs more investigation to conclude it's an actual bug and removed bug 🐛 An unexpected issue that highlights incorrect behavior labels Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mvvm-toolkit 🧰 Issues/PRs for the MVVM Toolkit needs author feedback 📝 This issue or PR needs a reply from the author unverified ⌛ Needs more investigation to conclude it's an actual bug
Projects
None yet
Development

No branches or pull requests

2 participants