Skip to main content

How to Resolve Error "CS0431: Cannot use alias 'identifier' with '::' since the alias references a type. Use '.' instead." in C#

The Compiler Error CS0431 is a syntax error regarding the Namespace Alias Qualifier (::). The message reads: "Cannot use alias 'MyAlias' with '::' since the alias references a type. Use '.' instead."

In C#, the double-colon operator :: is designed specifically to navigate aliases that point to Namespaces (like global::System or extern alias MyLib). If you create an alias that points to a specific Class (a Type), you cannot use :: to access its members. You must use the standard dot operator . just like you would with any other variable or class name.

This guide explains the difference between Namespace Aliases and Type Aliases and how to fix this syntax error.

Understanding :: vs .

  • :: (Namespace Alias Qualifier): Used only when the identifier on the left is an alias for a Namespace. This is helpful to disambiguate between two namespaces with the same name.
  • . (Member Access Operator): Used when the identifier on the left is a Namespace, Type, or Variable.

CS0431 happens when you define using MyAlias = MyClass; and then try to write MyAlias::MyMember. Since MyAlias points to a class, :: is invalid.

Scenario: The Invalid Qualifier on a Type

This error typically occurs when a developer creates a shorthand alias for a long class name and habitually uses the double-colon syntax, perhaps confusing it with C++ scope resolution or C# extern alias usage.

Example of error:

using System;

// 'ConsoleAlias' is an alias for a TYPE (System.Console class)
using ConsoleAlias = System.Console;

public class Program
{
static void Main()
{
// ⛔️ Error CS0431: Cannot use alias 'ConsoleAlias' with '::'
// since the alias references a type. Use '.' instead.
ConsoleAlias::WriteLine("Hello World");
}
}

Solution: Use the Dot Operator

Since the alias resolves to a class, treating it like a class is the correct approach. Simply replace :: with ..

Solution:

using System;

// Alias points to a Type
using ConsoleAlias = System.Console;

public class Program
{
static void Main()
{
// ✅ Correct: Treat 'ConsoleAlias' exactly like 'System.Console'
ConsoleAlias.WriteLine("Hello World");
}
}

Valid Use Case for ::

To understand why :: exists, here is a scenario where it is required. It is used when the alias points to a Namespace.

// Alias points to a Namespace
using Sys = System;

public class Program
{
static void Main()
{
// ✅ Correct: 'Sys' is a namespace, so '::' is allowed (though '.' also works).
// '::' is strictly required if you use 'extern alias'.
Sys::Console.WriteLine("Hello from Namespace Alias");
}
}

The most common valid use is global::System.Console.WriteLine(), where global is the root namespace alias.

Conclusion

CS0431 enforces the specific role of the double-colon operator.

  1. Check the Alias: Look at your using X = Y; statement.
  2. Is Y a Class? If Y is a class, struct, or interface, you must use X.Member.
  3. Is Y a Namespace? If Y is a namespace, you can use X::Member (or X.Member).