Skip to main content

How to Resolve Error "CS0538: Member in explicit interface declaration is not an interface" in C#

The Compiler Error CS0538 is a syntax error related to Explicit Interface Implementation. The message reads: " 'Name' in explicit interface declaration is not an interface".

In C#, you can implement an interface member explicitly by prefixing the member name with the interface name (e.g., void IMyInterface.MyMethod()). This error occurs when the name you put before the dot (.) is not an interface. It might be a Class, a Struct, or a Namespace. Since you can only "implement" interfaces, prefixing a method with a class name is invalid syntax.

This guide explains how to identify the incorrect type reference and fix the declaration.

Understanding Explicit Implementation Syntax

Explicit interface implementation allows a class to implement an interface member without exposing it as a public method of the class itself.

  • Syntax: ReturnType InterfaceName.MemberName(Params) { ... }
  • Requirement: InterfaceName must resolve to a valid interface type.

If InterfaceName resolves to a class, the compiler raises CS0538, effectively saying: "You are trying to implement a member of a Class explicitly, but you can only do that for Interfaces."

Scenario 1: Confusing Classes with Interfaces

This is the most common cause. You might be inheriting from a Base Class and trying to "implement" its method explicitly, thinking it works like an interface.

Example of error

public class BaseLogger
{
public void Log() { }
}

public class FileLogger : BaseLogger
{
// ⛔️ Error CS0538: 'BaseLogger' in explicit interface declaration is not an interface.
// 'BaseLogger' is a class. You cannot "explicitly implement" a class method.
void BaseLogger.Log()
{
// ...
}
}

Solution: Use override or new

If you are dealing with a Class, you don't use explicit implementation syntax. You use standard inheritance keywords.

  • If the base is virtual: Use override.
  • If the base is not virtual: Use new (shadowing) or simply define the method normally if you don't care about hiding.
public class FileLogger : BaseLogger
{
// ✅ Correct: Standard method definition (Shadowing the parent)
public new void Log()
{
// ...
}
}

Scenario 2: Typo in the Interface Name

Sometimes you have both a Class and an Interface with similar names (e.g., Logger and ILogger), and you accidentally type the class name.

Example of error

public interface ILogger
{
void Log();
}

public class Logger
{
// Implementation helper...
}

public class SystemLog : ILogger
{
// ⛔️ Error CS0538: 'Logger' is a class, not an interface.
void Logger.Log()
{
}
}

Solution: Correct the Name

Ensure the prefix refers to the interface definition.

public class SystemLog : ILogger
{
// ✅ Correct: 'ILogger' is the interface.
void ILogger.Log()
{
}
}

Conclusion

CS0538 is a simple type-checking error.

  1. Check the Prefix: Look at the name before the dot: Name.Method().
  2. Verify the Type: Is Name an interface?
    • If No (it's a Class): Remove the prefix. Use override or standard method syntax.
    • If No (it's a Typo): Correct the spelling to match the interface you intended to implement.