-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
I ran into this issue today and wanted to document it.
void Start() {
ObjectiveCRuntime.Initialize();
var x = NSApplication.NSApplicationLaunchRemoteNotificationKey;
}
Running that I get MethodNotFoundException.
What seems to happen is Start() is JIT compiled, NSApplicationLaunchRemoteNotificationKey is resolved, which resolves ObjectiveCRuntime.GetExtern() which internally uses GetInstanceInternal. The latter is an internal method which hasn't been registered yet because the bridge hasn't been bootstrapped because ObjectiveCRuntime.Initialize() hasn't actually executed yet. More specifically, the static constructor for ObjectiveCRuntime hasn't executed yet because Start() is still being compiled.
Moving the constant extern to a separate method works around it.
void Start() {
ObjectiveCRuntime.Initialize();
CheckConstant();
}
void CheckConstant() {
var x = NSApplication.NSApplicationLaunchRemoteNotificationKey;
}