Started using realm with version 4 and in the past week upgraded codebase to use Realm 5, since then we started seeing many crashes:
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=6 "Opening Realm files of format version 0 is not supported by this version of Realm" UserInfo={Error Code=6, NSFilePath=/var/mobile/Containers/Data/Application/E3935251-F5F7-427B-AB45-5CADF2037DF3/Documents/realm/2020-06-21T15-04-26.16604697742000.realm, Underlying=Database has an unsupported version and cannot be upgraded Exception backtrace:
I'm not able identify what exactly is causing those issues. I did try to update to version 5.2 and this introduced more random crashes
Realm files are using encryption.
No crashes.
Crashes to random users
Realm framework version: 5.1
Realm Object Server version: --
Xcode version: 11.5
iOS/OSX version: --
Dependency manager + version: Cocoapods
Hi @vikmeup Can you please post the full stack trace?
Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=6 "Opening Realm files of format version 0 is not supported by this version of Realm" UserInfo={Error Code=6, NSFilePath=/var/mobile/Containers/Data/Application/1123E220-F99D-42FE-853A-3E7F79D9886F/Documents/123.realm, Underlying=Database has an unsupported version and cannot be upgraded Exception backtrace: 0 Realm 0x0000000101862dd8 _ZN5realm2DB7do_openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbbNS_9DBOptionsE + 5324 1 Realm 0x0000000101864ee8 _ZN5realm2DB4openERNS_11ReplicationENS_9DBOptionsE + 244 2 Realm 0x00000001018693c0 _ZN5realm2DB6createERNS_11ReplicationENS_9DBOptionsE + 392 3 Realm 0x000000010163b6d0 _ZN5realm5_impl16RealmCoordinator7open_dbEv + 1156 4 Realm
Crashed: com.apple.main-thread
0 libswiftCore.dylib 0x19d42bfb4 _assertionFailure(_:_:file:line:flags:) + 800
1 libswiftCore.dylib 0x19d45eddc swift_unexpectedError + 436
... Internal calls, nothing related to realm. But this is where we call init and create realm object (this code did not change prior to realm 5)
7 UIKitCore 0x193d2f988 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 360
8 UIKitCore 0x193d31768 -[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 5104
9 UIKitCore 0x193d37164 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1256
10 UIKitCore 0x1934a703c -[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 152
11 UIKitCore 0x193972d68 _UIScenePerformActionsWithLifecycleActionMask + 112
12 UIKitCore 0x1934a7b70 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 212
13 UIKitCore 0x1934a759c -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 296
14 UIKitCore 0x1934a798c -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 756
15 UIKitCore 0x1934a7214 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 340
16 UIKitCore 0x1934ab930 __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke_2 + 196
17 UIKitCore 0x193891604 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:] + 856
18 UIKitCore 0x19398ca0c _UISceneSettingsDiffActionPerformChangesWithTransitionContext + 260
19 UIKitCore 0x1934ab66c __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 156
20 UIKitCore 0x19398c8f4 _UISceneSettingsDiffActionPerformActionsWithDelayForTransitionContext + 108
21 UIKitCore 0x1934ab4c4 -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 392
22 UIKitCore 0x193311ba4 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 640
23 UIKitCore 0x1933106a4 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 256
24 UIKitCore 0x1933118d4 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 236
25 UIKitCore 0x193d353fc -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 552
26 UIKitCore 0x1938b7e08 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 376
27 FrontBoardServices 0x194e52ffc -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 440
28 FrontBoardServices 0x194e795a0 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.168 + 116
29 FrontBoardServices 0x194e5debc -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 240
30 FrontBoardServices 0x194e79234 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 344
31 libdispatch.dylib 0x18f89033c _dispatch_client_callout + 20
32 libdispatch.dylib 0x18f8930d4 _dispatch_block_invoke_direct + 264
33 FrontBoardServices 0x194e9f6c4 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 48
34 FrontBoardServices 0x194e9f370 -[FBSSerialQueue _queue_performNextIfPossible] + 432
35 FrontBoardServices 0x194e9f8dc -[FBSSerialQueue _performNextFromRunLoopSource] + 32
36 CoreFoundation 0x18fb6baf4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
37 CoreFoundation 0x18fb6ba48 __CFRunLoopDoSource0 + 84
38 CoreFoundation 0x18fb6b198 __CFRunLoopDoSources0 + 196
39 CoreFoundation 0x18fb65f38 __CFRunLoopRun + 796
40 CoreFoundation 0x18fb658f4 CFRunLoopRunSpecific + 480
41 GraphicsServices 0x199f7c604 GSEventRunModal + 164
42 UIKitCore 0x193d39358 UIApplicationMain + 1944
43 Trust 0x1006ba7a0 main + 14 (RuleDecimalAmount.swift:14)
44 libdyld.dylib 0x18f9e12dc start + 4
I am seeing this as well, upgrading from 3.21 to 5.x seems to trigger that exact same issue in our App.
We are running RealmSwift via SPM and using encryption.
The issue does not seem to occur when we're trying to reproducing in debug builds, it only seems to be happening when running adhoc/release builds.
@vikmeup @leemaguire after a lot of testing, we might be able to provide a bit more information as the cause of this issue.
We noticed that this issue only occurs when the new version of our app has at the same time:
Realm.Configuration.schemaVersion It seems like Realm 5.x has an issue with migrating the DB while also migrating the Realm file format, since according to 5.0.0 release notes.
NOTE: This version bumps the Realm file format to version 10. It is not possible to downgrade version 9 or earlier. Files created with older versions of Realm will be automatically upgraded. Only Studio 3.11 or later will be able to open the new file format.
The only way to fix this so far is to upgrade our Realm Version to 4.4.1 only instead of 5.x, which luckily, is possible for us since we caught that before releasing our application.
I understand that is not something possible with developers that made that migration and shipped it, but hopefully provides a bit more information to find the issue.
@crousselle2 This has to be fixed urgently, we have some critical data stuck due this bug.
Could anyone experiencing an issue please upgrade to Realm 5.3.3 Thanks!

I'm getting this on Realm Studio and I've used RealmSwift 5.3.6
I assume you use encryption in this case. If so, the root cause of this issue has been found.
Most helpful comment
@vikmeup @leemaguire after a lot of testing, we might be able to provide a bit more information as the cause of this issue.
We noticed that this issue only occurs when the new version of our app has at the same time:
Realm.Configuration.schemaVersionIt seems like Realm 5.x has an issue with migrating the DB while also migrating the Realm file format, since according to 5.0.0 release notes.
The only way to fix this so far is to upgrade our Realm Version to 4.4.1 only instead of 5.x, which luckily, is possible for us since we caught that before releasing our application.
I understand that is not something possible with developers that made that migration and shipped it, but hopefully provides a bit more information to find the issue.