@@ -24,6 +24,15 @@ f1_keywords:
2424 - " CS1695"
2525 - " CS1696"
2626 - " CS1709"
27+ - " CS7009"
28+ - " CS7010"
29+ - " CS7011"
30+ - " CS8097"
31+ - " CS8098"
32+ - " CS8938"
33+ - " CS8939"
34+ - " CS8996"
35+ - " CS9028"
2736 - " CS9297"
2837 - " CS9298"
2938 - " CS9299"
@@ -51,6 +60,15 @@ helpviewer_keywords:
5160 - " CS1695"
5261 - " CS1696"
5362 - " CS1709"
63+ - " CS7009"
64+ - " CS7010"
65+ - " CS7011"
66+ - " CS8097"
67+ - " CS8098"
68+ - " CS8938"
69+ - " CS8939"
70+ - " CS8996"
71+ - " CS9028"
5472 - " CS9297"
5573 - " CS9298"
5674 - " CS9299"
@@ -83,6 +101,15 @@ The compiler generates the following errors for incorrect use of preprocessor di
83101- ** CS1695** : * Invalid #pragma checksum syntax; should be #pragma checksum "filename" "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" "XXXX..."*
84102- ** CS1696** : * Single-line comment or end-of-line expected*
85103- ** CS1709** : * Filename specified for preprocessor directive is empty*
104+ - ** CS7009** : * Cannot use #r after first token in file*
105+ - ** CS7010** : * Quoted file name expected*
106+ - ** CS7011** : * #r is only allowed in scripts*
107+ - ** CS8097** : * #load is only allowed in scripts*
108+ - ** CS8098** : * Cannot use #load after first token in file*
109+ - ** CS8938** : * The #line directive value is missing or out of range*
110+ - ** CS8939** : * The #line directive end position must be greater than or equal to the start position*
111+ - ** CS8996** : * Raw string literals are not allowed in preprocessor directives*
112+ - ** CS9028** : * The #line span directive requires space before the first parenthesis, before the character offset, and before the file name*
86113- ** CS9297** : * ` #: ` directives cannot be after first token in file*
87114- ** CS9298** : * ` #: ` directives can be only used in file-based programs (` -features:FileBasedProgram ` )*
88115- ** CS9299** : * ` #: ` directives cannot be after ` #if ` directive*
@@ -557,3 +584,155 @@ class Test
557584 }
558585}
559586```
587+
588+ ## CS7009: Cannot use #r after first token in file
589+
590+ The [`#r ` directive ](../preprocessor -directives /preprocessor -r .md ) can only be used before any tokens appear in a script file . After the first token , it 's no longer allowed .
591+
592+ The following example generates CS7009 :
593+
594+ ```csharp
595+ // CS7009.cs
596+ using System ;
597+ #r "System.Collections" // CS7009
598+ ```
599+
600+ ## CS7010: Quoted file name expected
601+
602+ A filename was expected in a [preprocessor directive ](../preprocessor-directives.md), but it was not properly quoted.
603+
604+ The following example generates CS7010:
605+
606+ ```csharp
607+ // CS7010.cs
608+ #r System.Collections.dll // CS7010 - missing quotes
609+ ```
610+
611+ To fix this error , enclose the filename in quotes :
612+
613+ ```csharp
614+ #r "System.Collections.dll" // OK
615+ ```
616+
617+ ## CS7011: #r is only allowed in scripts
618+
619+ The [`#r ` directive ](../preprocessor -directives /preprocessor -r .md ) can only be used in C # scripts (.csx files ), not in regular C # source files .
620+
621+ The following example generates CS7011 :
622+
623+ ```csharp
624+ // CS7011.cs
625+ class Test
626+ {
627+ static void Main ()
628+ {
629+ #r "System.Collections" // CS7011
630+ }
631+ }
632+ ```
633+
634+ ## CS8097: #load is only allowed in scripts
635+
636+ The [`#load ` directive ](../preprocessor -directives /preprocessor -load .md ) can only be used in C # scripts (.csx files ), not in regular C # source files .
637+
638+ The following example generates CS8097 :
639+
640+ ```csharp
641+ // CS8097.cs
642+ class Test
643+ {
644+ static void Main ()
645+ {
646+ #load "helper.csx" // CS8097
647+ }
648+ }
649+ ```
650+
651+ ## CS8098: Cannot use #load after first token in file
652+
653+ The [`#load ` directive ](../preprocessor -directives /preprocessor -load .md ) can only be used before any tokens appear in a script file . After the first token , it 's no longer allowed .
654+
655+ The following example generates CS8098 :
656+
657+ ```csharp
658+ // CS8098.csx
659+ using System ;
660+ #load "helper.csx" // CS8098
661+ ```
662+
663+ ## CS8938: The #line directive value is missing or out of range
664+
665+ The [`#line ` directive ](../preprocessor-directives/preprocessor-line.md) requires a valid line number. Line numbers must be between 1 and 16,707,566.
666+
667+ The following example generates CS8938:
668+
669+ ```csharp
670+ // CS8938.cs
671+ #line // CS8938 - missing value
672+ #line 0 // CS8938 - out of range
673+ class Test { }
674+ ```
675+
676+ To fix this error , provide a valid line number :
677+
678+ ```csharp
679+ #line 100 // OK
680+ class Test { }
681+ ```
682+
683+ ## CS8939: The #line directive end position must be greater than or equal to the start position
684+
685+ When using the [`#line ` directive ](../preprocessor -directives /preprocessor -line .md ) with span syntax , the end position must be greater than or equal to the start position .
686+
687+ The following example generates CS8939 :
688+
689+ ```csharp
690+ // CS8939.cs
691+ #line (1 , 10 ) - (1 , 5 ) "file.cs" // CS8939 - end column < start column
692+ class Test { }
693+ ```
694+
695+ To fix this error , ensure the end position is not before the start position :
696+
697+ ```csharp
698+ #line (1 , 5 ) - (1 , 10 ) "file.cs" // OK
699+ class Test { }
700+ ```
701+
702+ ## CS8996: Raw string literals are not allowed in preprocessor directives
703+
704+ [Raw string literals ](../../misc /raw -string -literals .md ) cannot be used in [preprocessor directives ](../preprocessor -directives .md ). Use regular string literals instead .
705+
706+ The following example generates CS8996 :
707+
708+ ```csharp
709+ // CS8996.cs
710+ #pragma checksum """raw_string""" "{406EA660-64CF-4C82-B6F0-42D48172A799}" "hash" // CS8996
711+ class Test { }
712+ ```
713+
714+ To fix this error , use a regular string literal :
715+
716+ ```csharp
717+ #pragma checksum "filename.cs" "{406EA660-64CF-4C82-B6F0-42D48172A799}" "hash" // OK
718+ class Test { }
719+ ```
720+
721+ ## CS9028: The #line span directive requires space before the first parenthesis, before the character offset, and before the file name
722+
723+ The [`#line ` directive ](../preprocessor -directives /preprocessor -line .md ) with span syntax requires proper spacing between its components .
724+
725+ The following example generates CS9028 :
726+
727+ ```csharp
728+ // CS9028.cs
729+ #line (1 , 1 ) - (1 , 10 )"file.cs" // CS9028 - missing spaces
730+ class Test { }
731+ ```
732+
733+ To fix this error , add the required spaces :
734+
735+ ```csharp
736+ #line (1 , 1 ) - (1 , 10 ) "file.cs" // OK
737+ class Test { }
738+ ```
0 commit comments