Skip to content

MethodNotFoundException in GetExtern(), possibly during JIT #415

@aarononeal

Description

@aarononeal

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;
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions