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

System.TypeInitializationException in iOS share extension #1354

Closed
3 tasks
Schaefers opened this issue Apr 14, 2017 · 18 comments
Closed
3 tasks

System.TypeInitializationException in iOS share extension #1354

Schaefers opened this issue Apr 14, 2017 · 18 comments
Assignees
Labels

Comments

@Schaefers
Copy link

Goals

I'm trying to access my realm database, which is stored in the shared memory using an AppGroup.

Expected Results

Realm.GetInstance(Path) should return an valid instance of the Realm database.

Actual Results

Realm.GetInstance(Path) crashes throwing the exception below. It doesn't make any difference if I'm providing a path or using the instance method without parameters.

System.TypeInitializationException: The type initializer for 'Realms.Realm' threw an exception. ---> System.DllNotFoundException: realm-wrappers
  at at (wrapper managed-to-native) Realms.NativeCommon:register_notify_realm_changed (Realms.NativeCommon/NotifyRealmCallback)
  at Realms.Realm..cctor () [0x0002a] in <550621f4184f47c0bdfce087c391c293>:0
  --- End of inner exception stack trace ---
  at TestExtension.ActionViewController.ViewDidLoad () [0x00008] in /Users/christianschafers/Projects/Test/TestExtension/ActionViewController.cs:28

Steps to Reproduce

  1. Create an empty Xamarin.iOS project
  2. add a share extension
  3. install Realm using nuGet
  4. call Realm.GetInstance() in ViewDidLoad() in ActionViewController.cs

The issue first occurred in a bigger project, but I can't tell exactly when the Extension stopped working. It was working fine for a long time, than after some modifications on the main App, I was unable to get the Share Extension working again.

Code Sample

https://github.com/Schaefers/realm-share-extension

Version of Realm and Tooling

  • Realm Object Server Version: ?
  • Flavor:
    • Developer
    • Professional
    • Enterprise
  • Server OS & Version: ? (e.g. CentOS 6)
  • Client SDK Version: Realm 1.2.0
  • Client OS & Version: macOS 10.12.4
@karapigeon
Copy link

Hi @Schaefers. Thanks for reaching out. I wanted to let you know that we've received your issue and that someone will review what you've shared and follow-up soon. In the meantime, would you be able to specify what flavour of RMP you're using?

@Schaefers
Copy link
Author

Hi, if RMP stands for this https://realm.io/products/realm-mobile-platform/ - I'm not using any kind of cloud based storage, the database ist just on the device itself - just left the Flavor part in the issue, because it was in the template and had no idea what to select.

@nirinchev
Copy link
Member

Thanks for the report and the clarification. Just wanted to let you know it's public holiday right now in Denmark, so we'll look into the issue early next week.

@nirinchev
Copy link
Member

nirinchev commented Apr 18, 2017

This is indeed a bug on our part. We don't apply the necessary transformations for share extension projects. The current solution would be to downgrade to Realm 1.0.4.

Share extensions are not .exe's so the WeaveRealmAssemblyTarget ignores them. We should also fix WeaveRealmAssembly as it hardcodes AssemblyName.exe.

@nirinchev nirinchev self-assigned this Apr 18, 2017
@dirkoswanepoel
Copy link

Hi, this is also an issue if the DB is accessed from a DLL. Any news on when this will be fixed? Thanks

@nirinchev
Copy link
Member

Not sure what you mean by that. How are you accessing the database from a DLL?

@dirkoswanepoel
Copy link

dirkoswanepoel commented May 23, 2017

We have a separate DLL in which we have all our DB code, and where we create and access the Realm. This causes the same crash. This Sample Project shows it. Most of the code is copy paste from the Realm.io documentation.

@fealebenpae
Copy link
Member

@dirkoswanepoel looking at the project you linked to, you need to add the Realm package to your iOS App project, not just the library project.

@dirkoswanepoel
Copy link

@fealebenpae Thanks, that was an oversight in the sample. That does fix the problem with the sample app, but for some reason it doesn't with our production app which already has a reference to Realm in the main App project. We however have many other libraries that might be causing this, but staying on 1.0.4 is the only known way to stop this crash from happening.

@petersondrew
Copy link

Is there any other workaround besides downgrading to 1.0.4? We can't roll back to that version due to Mono 5. If you could point me in the right direction I'd be happy to take a stab at fixing it ;-)

@nirinchev
Copy link
Member

There are two points where we need to make adjustments:

It's not a huge code change, but would require some testing which is why we haven't resolved the issue yet. But we would be more than happy to review a PR :)

@Dids
Copy link

Dids commented Jun 7, 2017

I'm also seeing this when I have a .NET library (DLL) and either a library or console app for NUnit unit testing.
Realm's added as a dependency to both targets and the unit test project is referencing the .NET library project.

Additionally, it doesn't seem to make a different whether the unit test target is a library or an executable, as the error stays the same.

@nirinchev
Copy link
Member

I'd be surprised if you're getting the same error - it's specific to iOS because that's the only application type that we modify the realm assembly for. It would be best to open a new issue and post as much detail as possible (ideally with a repro case).

@Schaefers
Copy link
Author

Now even 1.0.4 isn't working for me anymore. On iOS 10.3.2 the App crashes with this exception The type initializer for 'Realms.Realm' threw an exception. (System.TypeInitializationException), whereas I'm quite sure the build worked before. On the simulator with 10.3 debug builds are working fine - but I can't get release builds working.

Any ideas or an ETA when this issue will be addressed?

@fealebenpae
Copy link
Member

@Schaefers can you drill down into the exception and see what the inner exception is?

@Schaefers
Copy link
Author

System.EntryPointNotFoundException: realm_install_gchandle_deleter at (wrapper managed-to-native) Realms.NativeCommon:install_gchandle_deleter (Realms.NativeCommon/FreeGCHandleCallback) at Realms.NativeCommon.Initialize () <0x1000e6ca0 + 0x001c7> in <6a4aad7d9c894b85a92bb1ef490f2e66>:0 at Realms.Realm..cctor () <0x1000e71f0 + 0x0000f> in <6a4aad7d9c894b85a92bb1ef490f2e66>:0

does this help?

@fealebenpae
Copy link
Member

Did you update Xamarin Studio recently? Maybe a new version of Xamarin is not linking the old Realm package properly.

@Schaefers
Copy link
Author

Schaefers commented Jul 5, 2017

I'm not sure..since Xamarin is replaced by Visual Studio (which isn't working with these old versions), I'm avoiding any update. Will try with an older build later, but I don't think its possible to downgrade the Xamarin version anyway, because you won't find it online anymore.

Tried an old build, crashes with the same error, so may be an Xamarin bug, trying to find an older version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

9 participants