NetworkGetFirstEntityOwner throws MissingMethodException in C#

NetworkGetFirstEntityOwner consistently throws a TargetInvocationException—>MissingMethodException the first time it’s called, while the subsequent times it works regularly. My repro code:

[EventHandler("entityCreating")]
private async void OnEntityCreating(int entityHandle)
{
    try
    {
        var type = GetEntityType(entityHandle);
        var popType = GetEntityPopulationType(entityHandle);
        var owner = Players.Find(NetworkGetFirstEntityOwner(entityHandle));
        // ... irrelevant code ...
    }
    catch (Exception e)
    {
        // surprisingly the exception doesn't get caught here, it's probably
        // caught in the fivem runtime itself and printed there, otherwise
        // i would have logs in a file too but I don't
    }
}

As soon as the first player joins the server, this is what happens:

[       script:gtacnr] Error invoking callback for event entityCreating: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.MissingMethodException: Method not found: int CitizenFX.Core.Native.API.NetworkGetFirstEntityOwner(int)

[       script:gtacnr]   at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]   at Gtacnr.Server.Anticheat.AntiEntitySpawnScript.OnEntityCreating (System.Int32 entityHandle) [0x00024] in <84a3ba50f1d84ae5b9ea2b4ba996b9ce>:0 

[       script:gtacnr]   at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)

[       script:gtacnr]   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]    Exception_EndOfInnerExceptionStack

[       script:gtacnr]   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]   at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]   at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]   at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]   at CitizenFX.Core.EventHandlerEntry.Invoke (System.String sourceString, System.Object[] args) [0x00064] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\EventHandlerDictionary.cs:107 
[       script:gtacnr] Error invoking callback for event entityCreated: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.MissingMethodException: Method not found: int CitizenFX.Core.Native.API.NetworkGetFirstEntityOwner(int)

[       script:gtacnr]   at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]   at Gtacnr.Server.Anticheat.AntiEntitySpawnScript.OnEntityCreated (System.Int32 entityHandle) [0x00024] in <84a3ba50f1d84ae5b9ea2b4ba996b9ce>:0 

[       script:gtacnr]   at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)

[       script:gtacnr]   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]    Exception_EndOfInnerExceptionStack

[       script:gtacnr]   at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00083] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]   at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]   at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]   at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]   at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <fbc4ec45371543bfba3678ebb82caf6d>:0 

[       script:gtacnr]   at CitizenFX.Core.EventHandlerEntry.Invoke (System.String sourceString, System.Object[] args) [0x00064] in C:\gl\builds\4ff63adb\0\cfx\fivem\code\client\clrcore\EventHandlerDictionary.cs:107 

This only happens once, all the subsequent times the method works fine.

FXServer-master SERVER v1.0.0.4394 win32

I just realized it actually NetworkGetFirstEntityOwner no longer works, both in entityCreating and entityCreated, but I remember it used to work. I believe using NetworkGetEntityOwner in entityCreating should be reliably tell me the actual client that spawned the entity, right? If so, I could create a dictionary of mission entities that tells me the initial owner.

Try 4404 or higher.