Skip to main content

How to Resolve Error "CS0694: Type parameter has the same name as the containing type or method" in C#

The Compiler Error CS0694 is a naming conflict error involving Generics. The message reads: "Type parameter 'identifier' has the same name as the containing type, or method."

In C#, when you define a generic class (e.g., class List<T>) or a generic method (e.g., void Print<T>), the text inside the angle brackets < > creates a new identifier (a placeholder). The compiler strictly forbids naming this placeholder the exact same string as the class or method that contains it. This prevents recursive ambiguity where the compiler cannot distinguish between the container itself and the generic argument.

This guide explains why this conflict happens and how to rename your type parameters to follow standard conventions.

Understanding Generic Type Parameters

The text inside the < > brackets is a Declaration, not a usage.

  • Declaration: public class Wrapper<T> means "I am creating a class named Wrapper that works with some unknown type I will call T."
  • Conflict: If you write public class Wrapper<Wrapper>, you are effectively saying "I am creating a class named Wrapper that works with some unknown type I will call Wrapper."

Now, inside the class, does the word Wrapper refer to the class itself (for constructors/statics) or the generic placeholder? Because this is ambiguous and circular, C# disallows it.

Scenario 1: Conflict with Class or Interface Name

This is the most common occurrence. It often happens when a developer mistakenly thinks they need to specify the type constraint inside the definition brackets, or simply makes a typo.

Example of error

Attempting to name the generic placeholder the same as the class.

// ⛔️ Error CS0694: Type parameter 'DataStore' has the same name as the containing type
public class DataStore<DataStore>
{
public DataStore Item { get; set; }
}

Solution: Use Standard Naming Conventions

Rename the type parameter. The standard convention in .NET is to use a single letter T or a descriptive name prefixed with T (e.g., TEntity, TValue).

// ✅ Correct: 'T' is distinct from 'DataStore'.
public class DataStore<T>
{
public T Item { get; set; }
}

// OR

// ✅ Correct: 'TData' is descriptive and distinct.
public class DataStore<TData>
{
public TData Item { get; set; }
}
note

Did you mean a Constraint? If you intended to restrict the generic type to be a specific subclass, use the where clause: public class SpecificStore<T> where T : SomeBaseClass

Scenario 2: Conflict with Method Name

The same rule applies to generic methods. The generic placeholder cannot share the name of the method itself.

Example of error

public class Utility
{
// ⛔️ Error CS0694: Type parameter 'Convert' has the same name as the method.
public void Convert<Convert>(string input)
{
// ...
}
}

Solution: Rename the Parameter

Use T or a descriptive name like TResult or TInput.

public class Utility
{
// ✅ Correct: 'T' is standard.
public void Convert<T>(string input)
{
// ...
}

// ✅ Correct: 'TOutput' is descriptive.
public TOutput ConvertTo<TOutput>(string input)
{
return default(TOutput);
}
}

Conclusion

CS0694 is a naming collision check.

  1. Check the Brackets: Look inside <...> on your class or method definition.
  2. Compare Names: Is the word inside the brackets identical to the word immediately before the brackets?
  3. Rename: Change the type parameter to T, TKey, TValue, or any other name that is distinct from the container.