Please help with Exception?


#1

Hi

Suddently I start to get this exception on our production .net core project. Where using Realm Database without any sync.

Realms.Exceptions.RealmException: MapViewOfFileFromApp() failed: Exec format error size: 1476395008 offset: 0
at Realms.NativeException.ThrowIfNecessary(Func`2 overrider)
at Realms.RealmConfiguration.CreateRealm(RealmSchema schema)
at Realms.Realm.GetInstance(RealmConfigurationBase config, RealmSchema schema)
at SyncServerCore.RealmHelper.GetDefaultRealm() in D:\home\site\repository\SyncServerCore\Helpers\RealmHelper.cs:line 17
at SyncServerCore.Repository.GetContentStatus() in D:\home\site\repository\SyncServerCore\Helpers\Repository.cs:line 108
at lambda_method(Closure , Object , Object[] )
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__12.MoveNext()

It happends when I try to get a reference to the realm database via this helper method:

public static Realm GetDefaultRealm()
{
	// TODO add some more nice migration stuff?

	return Realm.GetInstance(new RealmConfiguration() { ShouldDeleteIfMigrationNeeded = true });
}

Could anyone please help me with this exception? What does it mean and has my database been corrupted?

Cheers,
Kent


#2

Looks like you’re trying to open a fairly large Realm file - 1.4 GB. It’s possible the OS can’t allocate enough contiguous address space to memory map the file, especially if you’re on a 32bit Windows. Does this sound like a reasonable size for your Realm - do you store a lot of objects/files inside? If not, it’s possible there is a lot of unclaimed space and you can try compacting the Realm file.


#3

I’m running on a “Basic: 1 small” instance on Azure … I dont think i have that many objects in the realm, but maybe its a memory problem, as the instance only has 1.75gb in total … do you need to have the whole realm in memory?


#4

Realm doesn’t load the entire file into memory, but it does memory map it, so the OS has to reserve a contiguous region of memory to fit the Realm file. If your instance has 1.75 gb, it’s not surprising that the OS isn’t able to do so. You can either upgrade your instance to one with more RAM or compact the Realm file. In either case, if you’re not storing that many objects, it may indicate heavy fragmentation of the Realm file. The most likely reason for those are if you’re opening Realms on background threads without disposing them.


#5

Thanks for your quick reply, really appreciate it !

I will take a look into it, I think some of my object has a lot of data in them. Need to cleanup a little bit then.

Is the any way you can “lookup” if the db is fragmented? Or du you suggest I add compacting on startup?


#6

If you add a ShouldCompactOnLaunch callback, that’ll get called with two arguments - totalBytes and usedBytes. A fragmented database will have significantly lower value for usedBytes.