InvalidCastException at OnExplosiveThrownError

Hi Ty

Failed to call hook 'OnExplosiveThrown' on plugin 'RaidTracker v1.2.3' (InvalidCastException: Null object cannot be converted to a value type.)
at System.Convert.ChangeType (System.Object value, System.Type conversionType, System.IFormatProvider provider) [0x00029] in <fb001e01371b4adca20013e0ac763896>:0
at System.Convert.ChangeType (System.Object value, System.Type conversionType) [0x0000c] in <fb001e01371b4adca20013e0ac763896>:0
at Oxide.Core.Plugins.Plugin.Call[T] (System.String hook, System.Object[] args) [0x00008] in <ec05e0208c9149bba43236ca58fea105>:0
at Oxide.Plugins.RaidTracker.OnExplosiveThrown (BasePlayer player, BaseEntity entity) [0x00047] in <d46a15497d504758bcba9e50432b8492>:0
at Oxide.Plugins.RaidTracker.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x004c7] in <d46a15497d504758bcba9e50432b8492>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <80b90e8213db44b29ec2d4111764172c>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <ec05e0208c9149bba43236ca58fea105>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <ec05e0208c9149bba43236ca58fea105>:0

looks like EventManager is not loaded properly, or that Oxide is having a hard time finding it. I will simply the check for it to prevent the error

and to @Wulf

if (Convert.ToBoolean(EventManager?.Call("isPlaying", player)))​

should prevent any type of null reference exception from being thrown, even though this should never fail:

if (EventManager != null && EventManager.IsLoaded && EventManager.Call<bool>("isPlaying", player))​


I remember we had a discussion about EventManager vs EventManager != null being able to throw an exception at times. even though the exception here is being thrown at .Call<bool> trying to cast null as a boolean type. I am not sure how EventManager could make the call AND return null. so maybe this will help you pinpoint the cause? I am just using EventManager as an example as well... I dont believe there is any issue with the plugin itself

nivex

looks like EventManager is not loaded properly, or that Oxide is having a hard time finding it

If you haven't already, I'd use a check for null and IsLoaded() if calling other plugins.

sure, I will add that before it... as shown in the second snippet of code

so it would be:

if (EventManager != null && EventManager.IsLoaded && Convert.ToBoolean(EventManager?.Call("isPlaying", player)))​

convert to boolean is helpful because it will parse null and return false. removing the need to use success is bool and (bool)success as the return

You could do this as well:

EventManager.Call<bool>("isPlaying", player)​

You're already null checking, so no need for the ? in there.

aye, that is what I was using and it still threw an exception. so it's why I've rewrote it as that