NullReferenceException at OnEntityBuiltFixed

Failed to call hook 'OnEntityBuilt' on plugin 'TurretManager v1.0.7' (NullReferenceException: Object reference not set to an instance of an object)

at Oxide.Plugins.TurretManager+<OnEntityBuilt>c__AnonStorey0.<>m__0 (ProtoBuf.PlayerNameID x) [0x00000] in <cd18264780c14a12a096b229ab99eca2>:0

at System.Linq.Enumerable.Any[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x0002c] in <1b13ba6391c74847bbc3eddc86df7eee>:0

at Oxide.Plugins.TurretManager.OnEntityBuilt (Planner plan, UnityEngine.GameObject go) [0x000f1] in <cd18264780c14a12a096b229ab99eca2>:0

at Oxide.Plugins.TurretManager.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x000b8] in <cd18264780c14a12a096b229ab99eca2>:0

at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0

at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0

at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0


Started seeing this tonight. Any ideas?

FriendsAPI installed, error as follows:

(16:05:41) | Failed to call hook 'OnEntityBuilt' on plugin 'TurretManager v1.0.7' (NullReferenceException: Object reference not set to an instance of an object)
  at Oxide.Plugins.TurretManager.OnEntityBuilt (Planner plan, UnityEngine.GameObject go) [0x00119] in <ead96ecfb7244d348c00a3657ecf129b>:0 
  at Oxide.Plugins.TurretManager.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x000b8] in <ead96ecfb7244d348c00a3657ecf129b>:0 
  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0 
  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0 
  at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0​
@OrangeDoggo, I'd suggest checking if Friends is null before trying to create an array and loop over the result.

char[] friendsList = Friends?.Call("GetFriendList", plr.userID).ToString().ToArray();
foreach (char friend in friendsList)


The current code above is the culprit, which if Friends is null then you won't be able to create an array result from it nor loop through it.

In response to Wulf ():
@OrangeDoggo, I'd suggest checking if Friends is null before trying to create an array and loop over...
Thanks Wulf

Strange part is that friends api was installed, active and loaded before this plugin. It shouldn't have been null
In response to Pho3niX90 ():
Thanks Wulf

Strange part is that friends api was installed, active and loaded before this...
Using Friends here as well ..... 
In response to Wulf ():
@OrangeDoggo, I'd suggest checking if Friends is null before trying to create an array and loop over...
Hmm Alright,I'll check it out. Quite busy with irl stuff hence why no updates.

Merged post

I'm marking this as solved,I added a check if Friends is null. If this persists,feel free to say so.

Still seeing it, LOTS!


Failed to call hook 'OnEntityBuilt' on plugin 'TurretManager v1.0.8' (NullReferenceException: Object reference not set to an instance of an object)

at Oxide.Plugins.TurretManager+<OnEntityBuilt>c__AnonStorey0.<>m__0 (ProtoBuf.PlayerNameID x) [0x00000] in <d9f32938a8264b04a9aeeb625f1e7ea8>:0

at System.Linq.Enumerable.Any[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x0002c] in <1b13ba6391c74847bbc3eddc86df7eee>:0

at Oxide.Plugins.TurretManager.OnEntityBuilt (Planner plan, UnityEngine.GameObject go) [0x000fc] in <d9f32938a8264b04a9aeeb625f1e7ea8>:0

at Oxide.Plugins.TurretManager.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x000b8] in <d9f32938a8264b04a9aeeb625f1e7ea8>:0

at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0

at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0

at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0

 

Same here with friends api installed and "Auto Authorize Friends (Requires Friends API)": true,

[Error] Failed to call hook 'OnEntityBuilt' on plugin 'TurretManager v1.0.8' (NullReferenceException: Object reference not set to an instance of an object)
at Oxide.Plugins.TurretManager.OnEntityBuilt (Planner plan, UnityEngine.GameObject go) [0x00124] in <7d52b0d61ae74c3cb2ff3ae83a684029>:0

at Oxide.Plugins.TurretManager.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x000b8] in <7d52b0d61ae74c3cb2ff3ae83a684029>:0

at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0

at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0

at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0
@OrangeDoggo, the issue would still be happening if your friendsList variable is null, as you can't loop over null. Using a character array wouldn't really provide you with the result you want, as the method provides a ulong array (or string array if you use the alternative one).

Change:
char[] friendsList = Friends?.Call("GetFriendList", plr.userID).ToString().ToArray();

To:
ulong[] friendsList = Friends.Call<ulong[]>("GetFriendList", plr.userID);

And then add a null check/empty after attempting to set that and before the iteration over it.

I have the Friends Auth set to true [yes i have it on the server] and I it does not work like it's intended nothing happens but I do get the Failed to call hook

(12:59:23) | Failed to call hook 'OnEntityBuilt' on plugin 'TurretManager v1.0.8' (NullReferenceException: Object reference not set to an instance of an object)

at Oxide.Plugins.TurretManager+<OnEntityBuilt>c__AnonStorey0.<>m__0 (ProtoBuf.PlayerNameID x) [0x00000] in <1e7a24825e3948e9b61d68041d6cf5c1>:0

at System.Linq.Enumerable.Any[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x0002c] in <1b13ba6391c74847bbc3eddc86df7eee>:0

at Oxide.Plugins.TurretManager.OnEntityBuilt (Planner plan, UnityEngine.GameObject go) [0x000fc] in <1e7a24825e3948e9b61d68041d6cf5c1>:0

at Oxide.Plugins.TurretManager.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x000b8] in <1e7a24825e3948e9b61d68041d6cf5c1>:0

at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0

at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0

at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0


http://prntscr.com/nelzmy  <--- Screenshot From console

This happens when someone puts a turret down and he has friends on his friendslist, any suggestions?

ive enable the option in the config and ive got friends api installed and ive added my friend to friend and he still gets targeted
In response to Wulf ():
@OrangeDoggo, the issue would still be happening if your friendsList variable is null, as you can't...
Im trying to implement your suggestions while waiting on OrangeDoggo to respond. 

Adding the above change on my test server including adding a null check before looping  im getting 

InvalidCastException: Object must implement IConvertible with the use of ulong ... Any suggestions , something i'm overlooking. 

Merged post

Never Mind I just noticed you listed your calls on your friends API dev notes. Ill work with those. 
Version:1.0.8    Current release

On my server using the latest oxide,loading is ok to check with o.plugins:
(20:35:41) | Listing 12 plugins:
...
  05 "Friends" (2.2.5) by Nogrod (0.09s) - Friends.cs
...
  11 "Turret Manager" (1.0.8) by Orange Doggo (0.04s) - TurretManager.cs​

But when I deploy a turret,it's show below error message on server console

(20:29:24) | Failed to call hook 'OnEntityBuilt' on plugin 'TurretManager v1.0.8' (NullReferenceException: Object reference not set to an instance of an object)
  at Oxide.Plugins.TurretManager+<OnEntityBuilt>c__AnonStorey0.<>m__0 (ProtoBuf.PlayerNameID x) [0x00000] in <787ed1d9c7c243da8a0d5349104546dd>:0

  at System.Linq.Enumerable.Any[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x0002c] in <3e4da02cf86b4fc686ed0ac61bffc210>:0

  at Oxide.Plugins.TurretManager.OnEntityBuilt (Planner plan, UnityEngine.GameObject go) [0x000fc] in <787ed1d9c7c243da8a0d5349104546dd>:0

  at Oxide.Plugins.TurretManager.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x000b8] in <787ed1d9c7c243da8a0d5349104546dd>:0

  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00079] in <9affce1cd15c4ec183941adef8db1722>:0

  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x000d8] in <4452f821def6406d834e4149849fe7ea>:0

  at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00060] in <4452f821def6406d834e4149849fe7ea>:0​

 

and then we got nothing happens,no fill and no toggle or autoauth
Updated the plugin,should be fixed. Marked the thread as fixed,if this issue occurs again,mark it as an error again.
Locked automatically