NullReferenceException at CanMoveItemFixed
Hello, despite re installing the plugin I keep getting this error in my console. 

(18:47:08) | Failed to call hook 'CanMoveItem' on plugin 'FurnaceSplitter v2.1.7' (NullReferenceException: Object reference not set to an instance of an object)
at Oxide.Plugins.FurnaceSplitter.CanMoveItem (Item item, PlayerInventory inventory, System.UInt32 targetContainer, System.Int32 targetSlot) [0x000ae] in <8c57f45e078a4eadb65c929828cb8c44>:0
at Oxide.Plugins.FurnaceSplitter.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00930] in <8c57f45e078a4eadb65c929828cb8c44>: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
This is still spamming my console, anyone have this issue too.. or?
@Wulf Any idea? I see you on here a lot and figure you might know.
In response to LazySloth ():
@Wulf Any idea? I see you on here a lot and figure you might know.
No sorry, but I'm sure someone will chime in if they do.
In response to Wulf ():
No sorry, but I'm sure someone will chime in if they do.
Alright, thanks.
Something is returning null in CanMoveItem which is causing the NRE. You'll need to find what variable, object or string is returning a null value. When a value is null it's empty. If you attempt to cast, convert or declare something that is null it will return an NRE if not properly null checked.

In this case, your function is CanMoveItem with the following arguments: Item item, PlayerInventory inventory, uint targetContainer, int targetSlot. One of these 'arguments' are either returning a null value or being cast from a null object.

 private object CanMoveItem(Item item, PlayerInventory inventory, uint targetContainer, int targetSlot)
        {
        }

First off, we need to ensure each argument is checked to make sure it is null. If so, we want to use a return behavior to stop the sequence. If we don't, it'll attempt to return a value where there is none.

 private object CanMoveItem(Item item, PlayerInventory inventory, uint targetContainer, int targetSlot)
        {
         if (item == null) return null;
         if (inventory == null) return null;
         if (targetContainer == null) return null;
        }​


If either one of our arguments is null, the sequence will be returned. If your error continues then one of your arguments is being cast as a non-null value to something that becomes null from another argument or object. In this case, we'd want to see which object is causing our NRE. To do this you'd want to print each value to console to see if either of them returns null. In this case, we want to print item, inventory, targetSlot, container, originalContainer to ensure they're not null.

Add the following to the code and ensure you do so AFTER everything is declared:

Puts($"Debug: {item} || {inventory} || {targetSlot} || {container} || {originalContainer}");

So it looks like this:

 private object CanMoveItem(Item item, PlayerInventory inventory, uint targetContainer, int targetSlot)
        {
         if (item == null) return null;
         if (inventory == null) return null;
         if (targetContainer == null) return null;
         //other code
         Puts($"Debug: {item} || {inventory} || {targetSlot} || {container} || {originalContainer}");
        }​

Keep an eye out for the debug that appears right before an NRE, that'll be your culprit.

In this case, originalContainer is returning null which is being cast from item.GetRootContainer. Let's null check originalContainer so if it does return null the sequence will be halted, preventing the NRE.

if (originalContainer == null) return null;

So at line 336, right under ItemContainer originalContainer = item.GetRootContainer(); (Because we want it to be declared first before we check if it's null) add the following line so your code resembles:

            BasePlayer player = inventory.GetComponent<BasePlayer>();
            if (player == null)
                return null;
            ItemContainer container = inventory.FindContainer(targetContainer);
            ItemContainer originalContainer = item.GetRootContainer();
            if (originalContainer == null) return null;

It's as simple as that! I would also invest time into why item is returning null sometimes but for now, the null check for originalContainer will suffice.

PS: I may refer to things inappropriately but you get the idea :P

In response to Death ():
Something is returning null in CanMoveItem which is causing the NRE. You'll need to find what variab...
Thanks <3
Hello,

This is what I get when players use the plugin.

http://prntscr.com/l6uj3e

How Can I fix it?

Ty,
Failed to call hook 'CanMoveItem' on plugin 'FurnaceSplitter v2.1.7' (NullReferenceException: Object reference not set to an instance of an object)
at Oxide.Plugins.FurnaceSplitter.CanMoveItem (Item item, PlayerInventory inventory, System.UInt32 targetContainer, System.Int32 targetSlot) [0x000ae] in <bc689f0b58084ecb9c78a76c41513e4e>:0

at Oxide.Plugins.FurnaceSplitter.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00930] in <bc689f0b58084ecb9c78a76c41513e4e>: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


(Filename: /home/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
deleted. already posted above.

(07:27:56) | Failed to call hook 'CanMoveItem' on plugin 'FurnaceSplitter v2.1.7' (NullReferenceException: Object reference not set to an instance of an object) at Oxide.Plugins.FurnaceSplitter.CanMoveItem (Item item, PlayerInventory inventory, System.UInt32 targetContainer, System.Int32 targetSlot) [0x000ae] in <36b3521e012246baa390cf4ce9541981>:0

at Oxide.Plugins.FurnaceSplitter.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00930] in <36b3521e012246baa390cf4ce9541981>: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


  • Failed to call hook 'CanMoveItem' on plugin 'FurnaceSplitter v2.1.7' (NullReferenceException: Object reference not set to an instance of an object) at Oxide.Plugins.FurnaceSplitter.CanMoveItem (Item item, PlayerInventory inventory, System.UInt32 targetContainer, System.Int32 targetSlot) [0x000ae] in <7983240cf65342ba959fb021f2c30817>:0
    at Oxide.Plugins.FurnaceSplitter.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00930] in <7983240cf65342ba959fb021f2c30817>: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
Hello! It often began to write in the console


This dosent break the plugin, but it is annoying, any fox for:

| Failed to call hook 'CanMoveItem' on plugin 'FurnaceSplitter v2.1.7' (NullReferenceException: Object reference not set to an instance of an object)

at Oxide.Plugins.FurnaceSplitter.CanMoveItem (Item item, PlayerInventory inventory, System.UInt32 targetContainer, System.Int32 targetSlot) [0x000ae] in <4ee20bc3619d474485a2c955a37b7ba7>:0

at Oxide.Plugins.FurnaceSplitter.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00930] in <4ee20bc3619d474485a2c955a37b7ba7>: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

This happens several times, really clogs up the console

 

Locked automatically