Skip to content
RustPluginGenerator
CS1061Oxide + Carbon

Fix CS1061: 'List<Item>' does not contain a definition for 'Where' (Oxide)

CS1061 means the compiler cannot find the member or extension method you called. For 'List<Item>' plus 'Where', 'Select', 'Any', 'FirstOrDefault' and similar methods, the fix is adding `using System.Linq;` at the top of the plugin file.

Server console
Error while compiling InventoryCleaner:
[1] 'List<Item>' does not contain a definition for 'Where' and no accessible extension method 'Where' accepting a first argument of type 'List<Item>' could be found (are you missing a using directive or an assembly reference?) at 28:38

Why it happens

LINQ methods such as Where, Select, Any, Count, OrderBy, FirstOrDefault and ToList are extension methods. They are not members of List<T>; they live in the System.Linq namespace. If the file does not import that namespace, the compiler only sees the members defined on List<Item> (such as Add, Remove, Count), so players.inventory.containerMain.itemList.Where(...) produces CS1061 and suggests a missing using directive. Oxide compiles each .cs file on its own with a fixed set of default usings; System.Linq is not guaranteed to be among them, and it is never added implicitly. The same error appears for other extension methods from System.Linq and for real typos in a member name, so read the message: when it names a LINQ operator on a collection type, the namespace is missing.

How to fix it

  1. Open the file named in the console line (here InventoryCleaner.cs).
  2. Add using System.Linq; to the block of using directives at the top of the file, outside the namespace.
  3. Save the file. Oxide detects the change and recompiles automatically; you can also force it with oxide.reload InventoryCleaner.
  4. Watch the console: a fixed plugin prints Loaded plugin <Title> v<Version> by <Author> and no Error while compiling line. If the numbered error is still there, read the new message; it may point at a different missing namespace or a genuine typo in a property name.
  5. Confirm in game: run the chat command the plugin registers and check the result.

If you prefer to avoid the dependency, rewrite the query as a plain foreach loop over itemList and collect what you need in a local list. That compiles without any using directive, but LINQ is usually the shorter option.

Before and after

BeforeFails
using System.Collections.Generic;
using Oxide.Core;
using Oxide.Core.Plugins;

namespace Oxide.Plugins
{
    [Info("Inventory Cleaner", "RustPluginGenerator", "1.0.0")]
    [Description("Counts and removes stacked junk items from a player's main inventory")]
    public class InventoryCleaner : RustPlugin
    {
        private const int JunkLimit = 20;

        [ChatCommand("clean")]
        private void CmdClean(BasePlayer player, string command, string[] args)
        {
            if (player == null)
            {
                return;
            }

            var main = player.inventory?.containerMain;
            if (main == null)
            {
                return;
            }

            // LINQ query without importing System.Linq
            var junk = main.itemList.Where(item => item != null && item.amount < 2).ToList();

            if (junk.Count == 0)
            {
                SendReply(player, "Nothing to clean.");
                return;
            }

            foreach (var item in junk)
            {
                item.Remove();
            }

            SendReply(player, "Removed " + junk.Count + " junk stack(s).");
        }

        [ConsoleCommand("inventorycleaner.count")]
        private void CcmdCount(ConsoleSystem.Arg arg)
        {
            var total = 0;
            foreach (var player in BasePlayer.activePlayerList)
            {
                var main = player.inventory?.containerMain;
                if (main != null)
                {
                    total += main.itemList.Count;
                }
            }

            arg.ReplyWith("Items in all main inventories: " + total);
        }
    }
}
AfterFixed
using System.Collections.Generic;
using System.Linq;
using Oxide.Core;
using Oxide.Core.Plugins;

namespace Oxide.Plugins
{
    [Info("Inventory Cleaner", "RustPluginGenerator", "1.0.0")]
    [Description("Counts and removes stacked junk items from a player's main inventory")]
    public class InventoryCleaner : RustPlugin
    {
        private const int JunkLimit = 20;

        [ChatCommand("clean")]
        private void CmdClean(BasePlayer player, string command, string[] args)
        {
            if (player == null)
            {
                return;
            }

            var main = player.inventory?.containerMain;
            if (main == null)
            {
                return;
            }

            var junk = main.itemList.Where(item => item != null && item.amount < 2).ToList();

            if (junk.Count == 0)
            {
                SendReply(player, "Nothing to clean.");
                return;
            }

            foreach (var item in junk)
            {
                item.Remove();
            }

            SendReply(player, "Removed " + junk.Count + " junk stack(s).");
        }

        [ConsoleCommand("inventorycleaner.count")]
        private void CcmdCount(ConsoleSystem.Arg arg)
        {
            var total = 0;
            foreach (var player in BasePlayer.activePlayerList)
            {
                var main = player.inventory?.containerMain;
                if (main != null)
                {
                    total += main.itemList.Count;
                }
            }

            arg.ReplyWith("Items in all main inventories: " + total);
        }
    }
}

FAQ

Is `using System.Linq;` inside the namespace Oxide.Plugins fine?

Yes. A using directive placed inside the namespace block is valid C# and works the same for the plugin's code. Put it at the top level of the file if you prefer the common style; both compile.

Why does the compiler only report one error when the file has several LINQ calls?

Roslyn reports the first batch of diagnostics it finds. After you add the using, save the file and Oxide recompiles; any remaining problem shows up as a new numbered line in the console.

The error names a method I did not call by that name. What now?

Check the line and column from the console message. A typo in a property or method name on Item or ItemContainer, for example itemLlst instead of itemList, produces the same CS1061 text.

Does Carbon need a different fix?

No. Carbon loads the same Oxide plugin file and compiles it with the same C# rules, so adding using System.Linq; fixes it there too. Only the console formatting of the error differs.

Different error?

Paste the full console output and get the cause and a fix in plain English.

Open the error explainer

Skip the debugging

Generated plugins are compiled before you get them, and compiler errors are fixed automatically.

Generate a plugin

2 free plugins a month, no card.

Last updated Oct 26, 2026.

Get plugins that compile first time

Generate