Realm Data Retrieval with .Net Standard 2.0 and Realm 4.2.0

I have been developing a program that interacts with a realm cloud database for the past several months now. During this time my code has worked fine until yesterday. Expected behavior: setup config, connect to realm and get instance, retrieve data into preset structure. Actual behavior, connects but retrieves no data, counts are all 0. Code:

    IQueryable<ExampleRoute> AllRoutes = null;
    IQueryable<ExampleAsset> AllAssets = null;
    List<ExampleTestEvent> AllTestEvents = null;

            var credentials = Credentials.UsernamePassword("Redacted", "Example", false);
            var admin =  await Realms.Sync.User.LoginAsync(credentials, new Uri($"Realm URL"));
            var u = new Uri("Correct path.");
            var config = new QueryBasedSyncConfiguration(u, admin, "c:\\test.file");

            using (var realm = Realm.GetInstance(config))
                AllRoutes = realm.All<ExampleRoute>();
                AllAssets = realm.All<ExampleAsset>();
                AllTestEvents = realm.All<ExampleTestEvent>().ToList();

                int RouteCount = AllRoutes.Count();
                int AssetCount = AllAssets.Count();
                int TestCount = AllTestEvents.Count();

My current hypothesis is that I lost connection mid transaction. Because this code worked exactly as intended until about noon yesterday. I had internet connection issues in my temp office, and this problem started up. It still connects to the realm server, however nothing comes back when I try to assign AllRoutes = realm.All();

Attempting to run the code with no internet connection results in an error, so I know that the code is connecting to the cloud not a local instance. I have tried deleting the test.file and any other files that are created on run. I have tried reverting to an old version of code that worked last month without my recent changes to the rest of the program.

I found a very old bug, Jan 2018, on the github that mentioned a similar problem, but was subsequently fixed in a later version of Realm. I am using the latest version available in Visual studio pro 2019, which is 4.2.0 with .Net Standard 2.0.

Any help would be appreciated as I have tried everything I can think of. I did create a support ticket request, but while waiting for a response there I wanted to see if anyone here knows how to solve this.

Have you checked with Realm Studio that your data is still there in Realm Cloud? I ask because when you lost and regained connectivity, I wonder if sync may have become confused and deleted your data.

Yes the data is still there and can be accessed through realm studio. Other devices can also retrieve and update data on the server using the same login information. The server is “fine”. Something local has gone screwy. Sorry for the technical terms here.

edit It may be useful to note that the other devices are not .Net, they are android devices that are operated on a completely different system by a different worker. I don’t have a lot more information than that.

The usual solution for us when this happens is uninstall and reinstall the app.

The app as in the Nuget Package? Tried that, The app as in the solution and all included folders? Could be done… was hoping to avoid that. I can restore from backup but it could get messy. I have tried a clean and rebuild, and deleted the debug and release folders.

I mean delete the runtime version of the app on the device and it’s folders. Not the VS solution.

Then that has been done. I deleted everything BUT the vs solution and required files for build, .cs etc.

What device are you running the .NET app on?

Windows 10 computer. I click build on the windows form app I have been working on and it does its thing. The most bare bones and simple program you could imagine. And like I said it worked exactly as expected right up until yesterday.

You’re using WinForms with .NET Standard 2.0? Do I understand you correctly?

Kind of… I seem to have unintentionally misled you. The win form uses .NET Framework 4.6.1 and has the code snippet above. It has the Realm Nuget Package installed on that project. The solution has the .Net Standard 2.0 installed, and the realm schema is saved in a dependent project that has .NET Standard 2.0… I am probably explaining this badly so I apologize for any confusion. I’m not even positive how the project uses .Net Framework and the solution has .net standard. It was set up by a far more experienced programmer and passed to me to continue to develop.

Just reading this I would probably point to this as the source of the problem, however, like I said, this worked for months prior to crashing yesterday. If this setup was the problem It wouldn’t have run without issues for so long.

I asked because when you uninstall a WinForms app it can leave stuff lying around.

When you reinstalled, were you prompted to login again? If you uninstall cleanly then Realm’s cached login will have been removed and you will have to login again. If you weren’t prompted to login again you may need to seek advice on how to do a clean uninstall of your app before running it again.

If you did login again, is it possible you logged in with different credtentials and accidentally created a new user? This would explain the lack of data. You can check Realm Studio to see if you have created a new user.

Okay, so the login all happens on the back end out of sight, you’ll see in the code above that a user is set up, the realm connection is created and logged in, and then I pull data from realm, so I wouldn’t know if it asked me to log in again or not. Files hanging around could definitely be the problem. I didn’t do an “Uninstall”, I just did a clean of the solution, deleted the debug and release folders, and anything else I could find. If there is somewhere else that this is leaving files or an actual uninstall option I am missing let me know.

I assume from the login code you show, although it is in another project, that project will run in the context of your machine and the login will be cached on your machine.

I think you will need to seek advice from your team on how to do a clean uninstall of your app from your machine.

Sorry I can’t be more helpful.

Going off of the code snippet in the first post, it doesn’t seem like you’re doing any subscriptions. Were the code for these omitted or really not present in your app?

Long travelling weekend, sorry for the delayed response. I am not doing subscriptions. The realm db has my user information, I use that user information to log in and retrieve data. It’s a one way transfer, from the realm db to the program for processing. Worked perfectly up till last Thursday.

You’re using query based sync (i.e. only data explicitly requested is synced), yet you’re not requesting any data in the form of a subscription. I’m not sure how that code worked before, but it was definitely not intended.