Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couldn't determine a writable folder where to store realm file. Specify absolute path manually. #1532

Closed
Schaefers opened this issue Aug 22, 2017 · 7 comments

Comments

@Schaefers
Copy link

Goals

Trying to create an realm instance on an iOS device using realm-dotnet

Expected Results

Getting a realm instance

Actual Results

{System.InvalidOperationException: Couldn't determine a writable folder where to store realm file. Specify absolute path manually.
  at Realms.InteropConfig+<>c.<.cctor>b__5_0 () [0x000e6] in <9229643aa1e4426e925ce96f833cdcbb>:0 
  at System.Lazy`1[T].CreateValue () [0x00081] in <5fd075b6ff6143c68dcfdd192b8757c5>:0 
  at System.Lazy`1[T].LazyInitValue () [0x00080] in <5fd075b6ff6143c68dcfdd192b8757c5>:0 
  at System.Lazy`1[T].get_Value () [0x0003a] in <5fd075b6ff6143c68dcfdd192b8757c5>:0 
  at Realms.InteropConfig.get_DefaultStorageFolder () [0x00000] in <9229643aa1e4426e925ce96f833cdcbb>:0 
  at Realms.RealmConfigurationBase.GetPathToRealm (System.String optionalPath) [0x00008] in <9229643aa1e4426e925ce96f833cdcbb>:0 
  at Realms.RealmConfigurationBase..ctor (System.String optionalPath) [0x00006] in <9229643aa1e4426e925ce96f833cdcbb>:0 
  at Realms.RealmConfiguration..ctor (System.String optionalPath) [0x00000] in <9229643aa1e4426e925ce96f833cdcbb>:0 
  at Realms.RealmConfiguration..cctor () [0x00000] in <9229643aa1e4426e925ce96f833cdcbb>:0 }

Steps to Reproduce

This just crashes on real hardware, simulator is working fine. Just try to create a new Realm.GetInstance() and deploy the application to an iOS device.

Code Sample

https://github.com/Schaefers/realm-share-extension (will be updated in a few minutes)

Version of Realm and Tooling

  • Visual Studio Community for Mac Version 7.1
  • Realm 1.6.0
  • iPhone 6s running iOS 10.3.3
@nirinchev
Copy link
Member

Are you getting the crash in your main application or your share extension? Currently, Realm Xamarin doesn't support share extensions due to #1354.

@Schaefers
Copy link
Author

It's in the main application.

@nirinchev
Copy link
Member

I haven't been able to reproduce it on my iPad. Can you try to clear your bin/obj folders and/or adding the realm nugets again?

@Schaefers
Copy link
Author

Yeah, problem still persists. Even building in a complete clean installed virtual machine doesn't fix it.

@nirinchev
Copy link
Member

nirinchev commented Aug 23, 2017

Sorry for the delay - I slightly modified your build environment which is why I didn't manage to reproduce it the first time. Looking at it again, the problem is that Realm is using Reflection to find the documents folder (this API is not available for .NET Standard). However, because on device you have enabled the linker, it strips the System.Environment API as it's unused. To fix the problem, you can add the following class to your assembly:

[Preserve(AllMembers = true)]
static class Preserver
{
    static void EnsurePreserved()
    {
        Environment.GetFolderPath(Environment.SpecialFolder.Personal);
    }
}

Let me know if that works for you and apologies again for not realizing this sooner.

@Schaefers
Copy link
Author

Works, thank you! ❤️

@nirinchev
Copy link
Member

Glad to hear that! If you face other issues, don't hesitate to reach out :)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants