Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
- "CS8914"
- "CS8915"
- "CS8933"
- "CS8954"
- "CS8955"
- "CS8956"
- "CS9130"
- "CS9131"
- "CS9132"
Expand All @@ -44,6 +47,9 @@
- "CS8914"
- "CS8915"
- "CS8933"
- "CS8954"
- "CS8955"
- "CS8956"
- "CS9130"
- "CS9131"
- "CS9132"
Expand Down Expand Up @@ -71,6 +77,9 @@
- [**CS8085**](#restrictions-on-using-aliases): *Error: A 'using static' directive cannot be used to declare an alias.*
- [**CS8914**](#global-using-directive): *Error: A global using directive cannot be used in a namespace declaration.*
- [**CS8915**](#global-using-directive): *Error: A global using directive must precede all non-global using directives.*
- [**CS8954**](#global-using-directive): *Error: A global using directive must precede all non-global using directives.*
- [**CS8955**](#global-using-directive): *Error: A file-local type cannot be used in a global using directive.*
- [**CS8956**](#using-directive-placement): *Error: A using directive must precede all other elements defined in the namespace except extern alias declarations.*
- [**CS9130**](#restrictions-on-using-aliases): *Error: Using alias cannot be a `ref` type.*
- [**CS9131**](#restrictions-on-using-aliases): *Error: Only a using alias can be `unsafe`.*
- [**CS9132**](#restrictions-on-using-aliases): *Error: Using alias cannot be a nullable reference type.*
Expand Down Expand Up @@ -107,6 +116,10 @@

Incorrectly combining a `using` directive with the `static`, `global`, or `unsafe` modifiers on a `using` directive are covered later in this article.

The compiler also produces **CS8956** when a using directive doesn't appear before other elements defined in a namespace (except extern alias declarations).


Check failure on line 121 in docs/csharp/language-reference/compiler-messages/using-directive-errors.md

View workflow job for this annotation

GitHub Actions / lint

Multiple consecutive blank lines

docs/csharp/language-reference/compiler-messages/using-directive-errors.md:121 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md012.md

Check failure on line 122 in docs/csharp/language-reference/compiler-messages/using-directive-errors.md

View workflow job for this annotation

GitHub Actions / lint

Multiple consecutive blank lines

docs/csharp/language-reference/compiler-messages/using-directive-errors.md:122 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 3] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md012.md
## Using static directive

The `using static` directive imports one type's members into the current namespace. The following example imports the methods from `System.Console`, such as `WriteLine` into the current namespace:
Expand Down Expand Up @@ -141,6 +154,15 @@

Furthermore, a `static global using` directive can't reference a [file-local](../keywords/file.md) type.

Violating these rules can also produce the following errors:

### CS8954

Check failure on line 159 in docs/csharp/language-reference/compiler-messages/using-directive-errors.md

View workflow job for this annotation

GitHub Actions / lint

Headings should be surrounded by blank lines

docs/csharp/language-reference/compiler-messages/using-directive-errors.md:159 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### CS8954"] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md022.md
A global using directive must precede all non-global using directives.

### CS8955

Check failure on line 162 in docs/csharp/language-reference/compiler-messages/using-directive-errors.md

View workflow job for this annotation

GitHub Actions / lint

Headings should be surrounded by blank lines

docs/csharp/language-reference/compiler-messages/using-directive-errors.md:162 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### CS8955"] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md022.md
A file-local type cannot be used in a global using directive.


Check failure on line 165 in docs/csharp/language-reference/compiler-messages/using-directive-errors.md

View workflow job for this annotation

GitHub Actions / lint

Multiple consecutive blank lines

docs/csharp/language-reference/compiler-messages/using-directive-errors.md:165 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md012.md
## Alias qualifier

The alias qualifier, [`::`](../operators/namespace-alias-qualifier.md), precedes a namespace alias, or follows the `global` alias. If you use `::` where `.` should be used to separate elements of a fully qualified name, the compiler emits one of **CS0431**, **CS0432**, **CS0687**, **CS7000*, or **CS8083**.
Expand Down
Loading