dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Executing RelayCommand throws System.MethodAccessException: Attempt by method

Open Symbai opened this issue 2 years ago • 0 comments

Describe the bug

I'm trying to figure out how to use a simple command which canexecute depends on a bool property. Unfortunately the sample application is heavily outdated as there are like 3 different ways of how to setup a command. And all of them are missing the canexecute step.

This is the exception I receive:

Unhandled exception. System.MethodAccessException: Attempt by method 'CompiledAvaloniaXaml.XamlIlTrampolines.xxx:xxx.ViewModels.MainWindowViewModel+LoginCommand_0!CommandExecuteTrampoline(System.Object, System.Object)' to access method 'xxx.ViewModels.MainWindowViewModel.LoginCommand()' failed.
   at CompiledAvaloniaXaml.XamlIlTrampolines.xxxx:xxx.ViewModels.MainWindowViewModel+LoginCommand_0!CommandExecuteTrampoline(Object, Object)

Anyway please see code below. Any help is appreciated

Regression

No response

Steps to reproduce

.NET 7
Avalonia

#
[ObservableProperty]
bool isNotLoggingIn = true;

[RelayCommand(CanExecute = nameof(IsNotLoggingIn))]
private async Task LoginCommand()
{
	IsNotLoggingIn = false;
	await Task.Delay(5000);
	IsNotLoggingIn = true;
}

Expected behavior

When I press the button the button should get disabled and after 5 seconds get enabled. But pressing the button throws the exception above.

Screenshots

No response

IDE and version

VS 2022 Preview

IDE version

No response

Nuget packages

  • [ ] CommunityToolkit.Common
  • [ ] CommunityToolkit.Diagnostics
  • [ ] CommunityToolkit.HighPerformance
  • [X] CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.2.2

Additional context

No response

Help us help you

No, just wanted to report this

Symbai avatar Nov 30 '23 08:11 Symbai