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

[AOT/Trim Support] ObservableRecipient.IsActive does not work #962

Open
1 of 4 tasks
ghost1372 opened this issue Oct 20, 2024 · 2 comments
Open
1 of 4 tasks

[AOT/Trim Support] ObservableRecipient.IsActive does not work #962

ghost1372 opened this issue Oct 20, 2024 · 2 comments
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior

Comments

@ghost1372
Copy link

Describe the bug

i always use ObservableRecipient and its IsActive property, now it seems that does not support AOT/Trim.

Solution:
i created a new property for this:
[ObservableProperty]
public bool isProcessActive;

Image

Regression

CommunityToolkit.Mvvm 8.3.2

Steps to reproduce

  1. Use ObservableRecipient and IsActive property
  2. Run app with PublishTrimmed and AOT

Expected behavior

Support AOT/Trim

Screenshots

No response

IDE and version

VS 2022

IDE version

No response

Nuget packages

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

Nuget package version(s)

8.3.2

Additional context

No response

Help us help you

No, just wanted to report this

@ghost1372 ghost1372 added the bug 🐛 An unexpected issue that highlights incorrect behavior label Oct 20, 2024
@ghost1372
Copy link
Author

@Sergio0694

@hawkerm
Copy link

hawkerm commented Nov 23, 2024

IsActive just calls either RegisterAll or UnregisterAll, these are not AOT safe, so that's the core issue.

Sergio had mentioned these should probably just end up being another source generator instead, so you don't have to manually register each interface either.

Could be a good, isolated generator issue for someone to pick up?

public partial class MyViewModel : ObservableRecipient, // or ObservableObject, etc...
    IRecipient<MyMessage1>,
    IRecipient<MyMessage2>
{
}

@Sergio0694 were you thinking it'd work like the DependencyInjection API and would there just be a partial RegisterMessages method or something added to OO?

public ObservableObject
{
    // New generated helper injection points
    partial RegisterMesssages();
    partial UnregisterMesssages();
}

Maybe these would be on OR, but in OO, the Messenger.RegisterAll method could then just go call RegisterMessages internally or something, right?

The generator would write these methods:

private void RegisterMessages()
{
    Register<MyMessage1>(this);
    Register<MyMessage2>(this);
}

private void UnregisterMessages()
{
   Unregister<MyMessage1>(this);
   Unregister<MyMessage2>(this);
}

Then IsActive would be:

public bool IsActive
{
    get;
    set
    {
        value ? RegisterMessages() : UnregisterMessages();
    }
}

It's late, so this is really rough, but it's just an initial thought to get things rolling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior
Projects
None yet
Development

No branches or pull requests

2 participants