Skip to main content

Keyword 'base' is not valid in a static member

In This Article

CodeRush Classic shows the Keyword ‘base’ is not valid in a static member code issue if the base keyword is used within a static member.

#Fix

Remove the reference to the base member or make the current member non-static.

#Purpose

Highlights the member declarations, which would cause the Keyword ‘base’ is not available in a static method compilation error.

#Example

public class MyBase
{
    public virtual void OutputText(string text)
    {
        Console.WriteLine(text);
    }
}
public class MyClass: MyBase
{
    public static void OutputText(string text)
    {base.OutputText(text);
    }
}

Fixes:

public class MyBase
{
    public virtual void OutputText(string text)
    {
        Console.WriteLine(text);
    }
}
public class MyClass: MyBase
{
    public static void OutputText(string text)
    {
        Console.WriteLine(text);
    }
}
public class MyBase
{
    public virtual void OutputText(string text)
    {
        Console.WriteLine(text);
    }
}
public class MyClass: MyBase
{
    public override void OutputText(string text)
    {
        base.OutputText(text);
    }
}