'Foo' is a 'Bar', which is not valid in the given context

This error is caused by identifier misuse, and can appear in many differing contexts.


Some examples of identifier misuse:

Omitting new from a constructor#

// 🔴 Incorrect:
Color color = Color(0, 0.5f, 0.9f, 1);
// 🟢 Should be:
Color color = new Color(0, 0.5f, 0.9f, 1);

Using a type in a context which isn't valid#

// 🔴 Incorrect:
Renderer renderer = GetComponent(Renderer);
// 🟢 Should be:
Renderer renderer = GetComponent<Renderer>();

Using a method like a class or variable#

public class Example
public void Foo () { }

// Foo can only be invoked like a method: Foo();
public void Bar () => Foo.Value;

You may have a method with the same name as a type. Either rename the method, or qualify that type through the use of its namespace.

Attempting to statically access a generic constraint#

public void Foo<T>() where T : IBar
// C# does not support this behaviour.
// Rethink your code structure to avoid this,
// or invoke the method directly via the specified static class.