Fix CS0120: An object reference is required for the non-static field, method, or property (Oxide)
CS0120 means you used a member of a type (for example BasePlayer.displayName) without an instance of that type, or you touched plugin instance members from a static method. Fix it by calling the member on a real object, or remove static from the method.
Error while compiling PlayerUtils: [1] An object reference is required for the non-static field, method, or property 'BasePlayer.displayName' at 21:45
Why it happens
In C#, instance members such as BasePlayer.displayName, player.ChatMessage(...), config.SomeField and every method of your plugin class belong to an object, not to the type itself. Writing the type name in front of them (BasePlayer.displayName) compiles only for static members. Oxide plugins hit this in two common ways: the code addresses a game type directly instead of a player variable, or the author marks a hook or helper static and then calls instance members like Puts, PrintWarning, lang.GetMessage, config or another plugin method from inside it. Oxide hooks must be non-static instance methods anyway, so the static keyword is a second bug hiding behind the first. The compiler points at the exact line and column, for example at 19:20 for BasePlayer.displayName.
How to fix it
- Read the line and column in the console message:
Error while compiling PlayerUtils: [1] ... at 19:20tells you where the offending expression is. - If the left side is a type name (
BasePlayer,ItemManager,StorageContainer), replace it with the variable that holds the object, or look it up first, e.g.BasePlayer player = BasePlayer.FindAwakeOrSleeping(args[0]);. - If the member is a plugin field or method (
config,Msg,Puts), the method containing it is probablystatic. Removestatic; Oxide hooks and chat commands are called on the loaded plugin instance. - Save the file. Oxide recompiles automatically and prints
Loaded plugin PlayerUtils v1.0.0 by RustPluginGenerator. Runoxide.reload PlayerUtilsif you want to force it and confirm no compile error appears.
Before and after
using System.Collections.Generic;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Player Utils", "RustPluginGenerator", "1.0.0")]
[Description("Shows a few facts about online players")]
public class PlayerUtils : RustPlugin
{
private int maxReports;
private void Init()
{
maxReports = 10;
}
[ChatCommand("whoami")]
private void CmdWhoAmI(BasePlayer player, string command, string[] args)
{
if (player == null) return;
player.ChatMessage("You are " + BasePlayer.displayName);
}
[ChatCommand("playerlist")]
private void CmdPlayerList(BasePlayer player, string command, string[] args)
{
if (player == null) return;
int shown = 0;
foreach (BasePlayer target in BasePlayer.activePlayerList)
{
if (target == null || !target.IsConnected) continue;
if (shown >= maxReports) break;
player.ChatMessage(target.displayName + " (" + target.UserIDString + ")");
shown++;
}
}
[ConsoleCommand("playerutils.count")]
private static void CcmdCount(ConsoleSystem.Arg arg)
{
arg.ReplyWith("Online: " + BasePlayer.activePlayerList.Count.ToString());
}
private void Unload()
{
Puts("PlayerUtils unloaded");
}
}
}using System.Collections.Generic;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Player Utils", "RustPluginGenerator", "1.0.0")]
[Description("Shows a few facts about online players")]
public class PlayerUtils : RustPlugin
{
private int maxReports;
private void Init()
{
maxReports = 10;
}
[ChatCommand("whoami")]
private void CmdWhoAmI(BasePlayer player, string command, string[] args)
{
if (player == null) return;
player.ChatMessage("You are " + player.displayName);
}
[ChatCommand("playerlist")]
private void CmdPlayerList(BasePlayer player, string command, string[] args)
{
if (player == null) return;
int shown = 0;
foreach (BasePlayer target in BasePlayer.activePlayerList)
{
if (target == null || !target.IsConnected) continue;
if (shown >= maxReports) break;
player.ChatMessage(target.displayName + " (" + target.UserIDString + ")");
shown++;
}
}
[ConsoleCommand("playerutils.count")]
private void CcmdCount(ConsoleSystem.Arg arg)
{
arg.ReplyWith("Online: " + BasePlayer.activePlayerList.Count.ToString());
}
private void Unload()
{
Puts("PlayerUtils unloaded");
}
}
}FAQ
Why does BasePlayer.displayName fail but player.displayName work?
displayName is a per-player field stored on each BasePlayer object. Writing the class name only works for members declared static. You need a reference such as BasePlayer player = arg.Player(); and then player.displayName. If the player is null (server console or RCON), guard with if (player == null) return;.
Can an Oxide hook be static?
No. Oxide resolves hooks by name and calls them on the plugin instance, and it also skips static methods. A static hook either is not called or produces CS0120 as soon as it uses instance members like Puts, lang.GetMessage or config. Remove static from every hook and chat command.
The line number in the error does not match my editing window. Why?
The console prints the line in the file Oxide compiled from oxide/plugins. If you edited a copy elsewhere, or an older build sits in the plugins folder, the numbers differ. Check oxide/logs for the full compiler output and make sure only one file with the same plugin name is present.
Does Carbon show the same error?
Yes. Carbon compiles the same C# and reports CS0120 as well, but prints the code with its own format instead of the numbered [1] ... at line:column list Oxide uses. The fix is identical: call the member on an instance and keep hooks non-static.
Different error?
Paste the full console output and get the cause and a fix in plain English.
Open the error explainerSkip the debugging
Generated plugins are compiled before you get them, and compiler errors are fixed automatically.
Generate a plugin2 free plugins a month, no card.
Last updated Oct 26, 2026.
Get plugins that compile first time
Generate