-
Type: Bug
-
Resolution: Cannot Reproduce
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
<!--- Questions: If you have questions about how to use Realm, please ask on -->
<!--- StackOverflow: http://stackoverflow.com/questions/ask?tags=realm -->
<!--- We monitor the
realm
tag. -->
<!--- Feature Request: Just fill in the first two sections below. -->
<!--- Bugs: To help you as fast as possible with an issue please describe your issue -->
<!--- and the steps you have taken to reproduce it in as much detail as possible. -->
<Unable to render embedded object: File (--- Thanks for helping us help you) not found. -->
Goals
Delete the Realm.
Expected Results
The Realm deletes without throwing an exception.
Actual Results
After calling
Realm.GetInstance(config).Dispose()
, I call
Realm.DeleteRealm(config)
which throws an exception
Realms.Exceptions.RealmPermissionDeniedException: Unable to delete Realm because it is still open.
Upon inspection of the instance realm via the debugger,
LocalStorage.IsClosed
is still false after calling
Dispose()
.
Something to note: This code has remained unchanged and has worked for nearly 2 years without issue, but upon upgrading to
Realm.Database
3.2, I started seeing this issue.
Steps to Reproduce
See above.
Code Sample
private Realm LocalStorage => Realm.GetInstance(GetRealmConfig()); public void Delete() { App.Log.Info("Deleting realm."); //delete data on device (realm) if (_config != null) { LocalStorage.Dispose(); Realm.DeleteRealm(_config); //throws exception here,crashing app; App.Log.Info("Realm deleted."); } //clear local db identifier (this will force app to generate a new realm) _localDbId = null; _appIo.SetPreference(AppPreference.DbIdentifier, null); _appIo.SetPreference(AppPreference.DbSchemaVersion, null); _config = null; } private RealmConfiguration GetRealmConfig() { return _config ?? (_config = BuildRealmConfig()); } private RealmConfiguration BuildRealmConfig() { var dbId = GetLocalDbId(); var dbName = $"prepify-{App.User.MemberInfo.MemberGuid}_{dbId}.realm"; var schema = GetSchemaVersion(); App.Log.Info($"Access realm: schema {schema} | id {dbId} | name {dbName}"); return new RealmConfiguration(dbName) { ShouldDeleteIfMigrationNeeded = true, SchemaVersion = schema }; } private ulong GetSchemaVersion() { return _appIo.GetPreference<ulong?>(AppPreference.DbSchemaVersion) ?? 1; } private int GetLocalDbId() { App.Log.Info($"getting dbId"); lock (_locker) { if (!_localDbId.HasValue) _localDbId = _appIo.GetPreference<int?>(AppPreference.DbIdentifier); if (!_localDbId.HasValue) { _localDbId = new Random(DateTime.Now.Millisecond).Next(111111, 999999); App.Log.Info($"set new dbId {_localDbId}; this will force generate a new realm when accessed"); _appIo.SetPreference(AppPreference.DbIdentifier, _localDbId); } } return _localDbId.Value; }
Version of Realm and Tooling
- Realm Object Server Version: n/a
- Flavor:
- [] Developer
- [ ] Professional
- [ ] Enterprise
- Server OS & Version: ? n/a
- Client SDK Version: Realm.Database 3.2
- Client OS & Version: iOS 11.4; NET Standard 2.0; XF 3.2
- is duplicated by
-
RNET-167 Realm.DeleteRealm(config) intermittenlty fails
- Closed