mooege/mooege — Issue #160: Inventory : System.InvalidOperationException : Nullable object must have a value
Author: PeteGet27
Created: 2011-10-11 22:38:19+00:00
State: open

Exception :
[Debug] [Server]: ReceiveCallback - [Exception] System.InvalidOperationException
: Nullable object must have a value.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resour
ce)
at System.Nullable`1.get_Value()
at Mooege.Core.GS.Player.Stash.AddItem(Item item) in D:\mooege\src\Mooege\Cor
e\GS\Player\Stash.cs:line 139
at Mooege.Core.GS.Player.Inventory.IsValidEquipmentRequest(Item item, Int32 e
quipmentSlot) in D:\mooege\src\Mooege\Core\GS\Player\Inventory.cs:line 238
at Mooege.Core.GS.Player.Inventory.HandleInventoryRequestMoveMessage(Inventor
yRequestMoveMessage request) in D:\mooege\src\Mooege\Core\GS\Player\Inventory.cs
:line 150
at Mooege.Core.GS.Player.Inventory.Consume(GameClient client, GameMessage mes
sage) in D:\mooege\src\Mooege\Core\GS\Player\Inventory.cs:line 316
at Mooege.Core.GS.Game.Game.Route(GameClient client, GameMessage message) in
D:\mooege\src\Mooege\Core\GS\Game\Game.cs:line 79
at Mooege.Net.GS.GameClient.Parse(ConnectionDataEventArgs e) in D:\mooege\src
\Mooege\Net\GS\GameClient.cs:line 76
at Mooege.Net.GS.GameServer.GameServer_DataReceived(Object sender, Connection
DataEventArgs e) in D:\mooege\src\Mooege\Net\GS\GameServer.cs:line 41
at Mooege.Net.Server.OnDataReceived(ConnectionDataEventArgs e) in D:\mooege\s
rc\Mooege\Net\Server.cs:line 216
at Mooege.Net.Server.ReceiveCallback(IAsyncResult result) in D:\mooege\src\Mo
oege\Net\Server.cs:line 127

Origin of the issue :

namespace Mooege.Core.GS.Player
{
///

/// This class handels the gridlayout of an stash. Possible usecases are the inventory backpack, shared stash, traders stash,...
/// Stash is organized by adding an item to EVERY slot it fills
///

public class Stash
{
///

/// Adds an Item at a free spot to the backpack
///

///
public void AddItem(Item item)
{
InventorySlot? slot = FindSlotForItem(item); <-------------------- INIT ISSUE CONDITION
AddItem(item, slot.Value.Row, slot.Value.Column); <-------------------- RAISE ISSUE EXCEPTION
}

In certain condition (i got this issue while playing on swap weapon 1H 2H & shield), null value assigned to slot then slot.XXX raise NullReferencePointerException-like

Main thread killed down so nothing respond anymore clientside (no disconnection) after this excep raise serverside.