Jump to content

Getting "Object reference not set to an instance of an object." error on event call.


Asokanta

Recommended Posts

Hey, I'm trying to add a custom event but getting "Object reference not set to an instance of an object" error instead. 

Exception details:

Spoiler

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at void RageInternal.Events+EventPusher.PushOne(object obj)
   at void RageInternal.Events+EventPusher.Push(params object[] args)
   at void RageInternal.Events.CallLocal(string eventName, params object[] args)
   at void RAGE.Events.CallLocal(string eventName, params object[] args)
   at void ExampleResource.Main.TriggerHelloWorld(Player sender) in TestScript.cs:line 86
   --- End of inner exception stack trace ---
   at object RuntimeMethodHandle.InvokeMethod(object target, object[] arguments, Signature sig, bool constructor, bool wrapExceptions)
   at object System.Reflection.RuntimeMethodInfo.Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
   at bool GTANetworkInternals.CommandParser.Parse(Player sender, string cmdRaw, string ourcmd, string[] args)

 

        [ServerEvent(Event.ResourceStart)]
        public void OnResourceStart()
        {
            Events.Add("sendhelloworld", SendHelloWorld);
        }


        private void SendHelloWorld(object[] args)
        {
            NAPI.Util.ConsoleOutput("Hello world.");
        }

        [Command("hey")]
        public void TriggerHelloWorld(Player sender)
        {
            Events.CallLocal("sendhelloworld", sender);
        }
Link to comment
Share on other sites

 public void TriggerHelloWorld(Player sender)
8 hours ago, hash_ said:

which is line 86?

 

I simplified that way so people can focus on error rather than code. I'm trying to understand why I'm getting that error.

5 hours ago, Xabi said:

Why would you call a serverside event like that when you can just call SendHelloWorld(sender)?

Edited by Asokanta
remove unnecessary lines
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...