Crash when dropping custom item with ItemContainer

I’ve created a custom item in my plugin.
It’s based on a normal rf.detonator, but it has an attached ItemContainer so players can insert “drives” into it (basically small access key items).

The item works fine while it’s in a player’s inventory, but if a player drags it off their hotbar/inventory to drop it, the server immediately throws a NullReferenceException and crashes.

Here’s what I’ve observed:

  • The crash happens even if I try to handle it in CanDropItem, CanMoveItem, OnDropItem, or OnItemRemovedFromContainer.

  • None of those hooks are triggered before the crash — it seems the problem occurs inside Rust’s internal DroppedItem creation logic.

  • It only happens when the custom ItemContainer on the item has contents (the “drives”).

  • Empty communicators can be dropped without issue.

  • Setting ItemDefinition.Flag.NoDropping or def.flags |= ... makes it undroppable in theory, but doesn’t help if the player is already holding an instance and tries to drag/drop it — still crashes.

Question:
Has anyone run into this before? Is there a way to completely prevent Rust from trying to spawn a dropped entity for an item, or to intercept the drag/drop action earlier than the existing item hooks?

I’m fine with blocking dropping entirely if there’s a reliable way to do it that works before DroppedItem spawns.

are you adding ItemModContainer component to it?

example

            var container = ItemManager.CreateByItemID(1397052267, 1, 0);

            if (container != null)
            {
                ItemModContainer component = container.info.GetOrAddComponent<ItemModContainer>();
                container.contents = new ItemContainer();
                container.contents.ServerInitialize(null, 60);
                container.contents.GiveUID();
                container.contents.parent = container;
                container.contents.Save();
                container.name = "Name";
                container.MarkDirty();
            }​