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

IRealmCollection SubscribeForNotifications not working!!! #3598

Open
GoodWayDev opened this issue May 7, 2024 · 6 comments
Open

IRealmCollection SubscribeForNotifications not working!!! #3598

GoodWayDev opened this issue May 7, 2024 · 6 comments
Assignees
Labels
App-type:Other More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. O-Community SDK-Use:Local T-Bug

Comments

@GoodWayDev
Copy link

What happened?

I used SubscribeForNotifications with IRealmCollection. After packaging the app into an MSIX for installation, I didn't receive any notifications when adding a new record. However, during local debugging, I could receive notifications.

Repro steps

  1. Implement SubscribeForNotifications on ViewModel init.
  2. Add a new record.
  3. SubscribeForNotifications didn't receive any notifications.

Version

8.0

What Atlas Services are you using?

Local Database only

What type of application is this?

Other

Client OS and version

Windows 10 22H2 build 19045.4291

Code snippets

DataService.cs

public class DataService
{
    public static DataService Instance { get; } = new DataService();

    private readonly Realm LocalRealm;

    public IRealmCollection<Device> DeviceList { get; }

    public async Task<Device> AddDevice(Device device)
    {
        return await LocalRealm.WriteAsync(() =>
        {
            return LocalRealm.Add(device, true);
        });
    }
}

ViewModel.cs

public partial class DeviceListViewModel : ObservableObject
{
    public ObservableCollection<Models.Device> DeviceList { get; } = [];

    private IDisposable deviceListNotifyToken;

    public DeviceListViewModel()
    {
        deviceListNotifyToken = DataService.Instance.DeviceList.SubscribeForNotifications((list, changeSet) =>
        {
            if (changeSet != null)
            {
                foreach (var idx in changeSet.InsertedIndices)
                    DeviceList.Insert(idx, list[idx]);

                foreach (var idx in changeSet.ModifiedIndices)
                {
                    var item = list[idx];
                    DeviceList.RemoveAt(idx);
                    DeviceList.Insert(idx, item);
                }

                foreach (var idx in changeSet.DeletedIndices)
                    DeviceList.RemoveAt(idx);
            }

            OnPropertyChanged();
        });
    }
}

Stacktrace of the exception/crash you're getting

No crash.

Relevant log output

No log.
Copy link

sync-by-unito bot commented May 7, 2024

➤ PM Bot commented:

Jira ticket: RNET-1144

@nirinchev
Copy link
Member

How is DeviceList populated and stored on the DataService object? Additionally, is there a reason why you're copying the objects from Realm into the observable collection? Why not just use the realm collection directly?

@nirinchev nirinchev added the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label May 8, 2024
@nirinchev nirinchev self-assigned this May 8, 2024
@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label May 8, 2024
@GoodWayDev
Copy link
Author

The DeviceList on the DataService is populated and stored by calling the AddDevice() from the DeviceManager class, which detects devices.
The reson why did not use IRealmCollection is because I don't want the ViewModel import Realm. But I've also tried with realm collection and the problem persists.

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels May 9, 2024
@nirinchev
Copy link
Member

Models.Device already imports Realm transitively, so unless you project that into a view model, you're still ending up with a Realm dependency.

In any case, I've tried creating a simple project (I only built it in release, haven't packaged it in MSIX) and can't reproduce the behavior - can you create a repro case that we can use to further investigate.

@nirinchev nirinchev added the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label May 9, 2024
@GoodWayDev
Copy link
Author

Thanks, I got it.
It only occurs after being packaged into an MSIX installer. During the development, build in either debug or release works fine. It's only when packaging it into an MSIX for the client that this issue arises.

@github-actions github-actions bot removed the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label May 10, 2024
@nirinchev
Copy link
Member

I tried packaging a simple WPF app in MSIX and wasn't able to repro the issue you're describing. I've attached a zipped version of the project I created - I can package that, install it, and it works as expected - clicking the "Add item" button will immediately update the listview. If you can confirm whether it works for you and/or modify it so that it reproduces the problem, I can continue looking into it.

Dotnet-3598.zip

@nirinchev nirinchev added the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label May 22, 2024
@sync-by-unito sync-by-unito bot removed the Needs-Attention Reporter has responded. Review comment. label May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
App-type:Other More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. O-Community SDK-Use:Local T-Bug
Projects
None yet
Development

No branches or pull requests

2 participants