Uploaded image for project: 'Realm .NET SDK'
  1. Realm .NET SDK
  2. RNET-561

[Bug]: Program "has exited with code -1073740791 (0xc0000409)" when opening synced realm from two applications at once

      What happened?

      When I call Realm.GetInstance from my .NET client code normally, it works fine. But if I then run another instance of my application, and call GetInstance, it exits unexpectedly, saying: The program has exited with code -1073740791 (0xc0000409). The Visual Studio debugger does not catch any exceptions or anything, the program just stops, reporting that message to the output.

      Best I can find on this exit code is this SO answer which suggests it might be a stack overrun..?

      There does seem to be a timing issue involved (maybe with async background threads??) because when I have tried stepping into each instruction, starting from the .GetInstance call, while normally it just exits, on one occasion I actually succeeded in getting a few instructions further - but then it still stopped with the same message a bit later.

      (Is this behaviour expected? Is my desired use supported? Should I be doing this another way?)

      Repro steps

      1. App.Create(appId)
      2. LogInAsync(apiKey)
      3. Realm.GetInstance(new SyncConfiguration(partition, user))
      4. <leave application running, start another instance of the same application>
      5. App.Create(appId)
      6. LogInAsync(apiKey)
      7. Realm.GetInstance(new SyncConfiguration(partition, user))

      Version

      Realm 10.5.1 / .NET 5.0

      What SDK flavour are you using?

      MongoDB Realm (i.e. Sync, auth, functions)

      What type of application is this?

      WPF

      Client OS and version

      Windows 10 Pro 21H1 19043.1237 64-bit operating system, x64-based processor Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz 16.0 GB RAM

      Code snippets

          private void Window_Loaded(object sender, RoutedEventArgs e)
          {
              Action action = async () => await ConnectToRealmAsync();
              Dispatcher.BeginInvoke(action, System.Windows.Threading.DispatcherPriority.Background);
          }
      
          private async Task ConnectToRealmAsync()
          {
              RealmStatus = "Connecting";
      
              Session.Error += (sender, errorArgs) =>
              {
                  Debug.WriteLine("Session Error: " + errorArgs.Exception.Message);
                  RealmStatus = errorArgs.Exception.Message;
              };
      
              try
              {
                  var app = Realms.Sync.App.Create(RealmAppId);
      
                  Debug.WriteLine($"app={app}");
      
                  var user = await app.LogInAsync(Credentials.ApiKey(RealmApiKey));
      
                  Debug.WriteLine($"user={user.Id}");
                  RealmStatus = "Logged in";
      
                  var config = new SyncConfiguration(user.Id, user);
                  var realm = Realm.GetInstance(config); // program exits here before returning to this function, on second instance of application
      
                  Debug.WriteLine($"realm={realm}");
                  RealmStatus = "Ready";
              }
              catch (Exception ex)
              {
                  Debug.WriteLine("Connection exception: " + ex.Message);
                  RealmStatus = ex.Message;
              }
      
          }
      

      Stacktrace of the exception/crash you're getting

      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      I wish I had a stacktrace!! All I get is:
      
      The program '[6332] RealmTestApp.exe' has exited with code -1073740791 (0xc0000409).
      

      Relevant log output

      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      app=Realms.Sync.App
      user=61345920826942f6487d4d57
      The program '[6332] RealmTestApp.exe' has exited with code -1073740791 (0xc0000409).
      

            Assignee:
            nikola.irinchev@mongodb.com Nikola Irinchev
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: