Skip to content

Commit f676788

Browse files
committed
Final edits
1 parent 4589ff0 commit f676788

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

docs/csharp/language-reference/compiler-messages/source-generator-errors.md

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -80,36 +80,36 @@ ms.date: 05/23/2025
8080
The following errors are generated when source generators or interceptors are loaded during a compilation:
8181

8282
- [**CS9137**](#interceptors-are-experimental): *The 'interceptors' experimental feature is not enabled. Add `<Features>InterceptorsPreview<Features>` to your project.*
83-
- [**CS9138**](#other-failures): *Method cannot be used as an interceptor because it or its containing type has type parameters.*
83+
- [**CS9138**](#incorrect-interceptor-declaration): *Method cannot be used as an interceptor because it or its containing type has type parameters.*
8484
- [**CS9139**](#incorrect-mapping): *Cannot intercept: compilation does not contain a file with path.*
8585
- [**CS9140**](#incorrect-mapping): *Cannot intercept: compilation does not contain a file with path. Did you mean to use a different path?*
8686
- [**CS9141**](#incorrect-mapping): *The provided line and character number does not refer to an interceptable method name, but rather to a token.*
8787
- [**CS9142**](#incorrect-mapping): *The given file has `n` lines, which is fewer than the provided line number `m`.*
8888
- [**CS9143**](#incorrect-mapping): *The given line is `c` characters long, which is fewer than the provided character number `n`.*
8989
- [**CS9144**](#signature-mismatch): *Cannot intercept method `M` with interceptor `V` because the signatures do not match.*
9090
- [**CS9145**](#incorrect-mapping): *Cannot intercept: Path is unmapped. Expected mapped path.*
91-
- [**CS9146**](#other-failures): *An interceptor method must be an ordinary member method.*
91+
- [**CS9146**](#incorrect-interceptor-declaration): *An interceptor method must be an ordinary member method.*
9292
- [**CS9147**](#incorrect-mapping): *The provided line and character number does not refer to the start of a token. Did you mean to use line `n` and character `c`?*
9393
- [**CS9148**](#signature-mismatch): *Interceptor must have a `this` parameter matching parameter.*
9494
- [**CS9149**](#signature-mismatch): *Interceptor must not have a `this` parameter because method does not have a `this` parameter.*
9595
- [**CS9150**](#incorrect-mapping): *Interceptor cannot have a `null` file path.*
96-
- [**CS9151**](#other-failures): *Possible method name `M` cannot be intercepted because it is not being invoked.*
97-
- [**CS9152**](#other-failures): *Cannot intercept a call in file with this path because multiple files in the compilation have this path.*
98-
- [**CS9153**](#other-failures): *The indicated call is intercepted multiple times.*
96+
- [**CS9151**](#incorrect-interceptor-declaration): *Possible method name `M` cannot be intercepted because it is not being invoked.*
97+
- [**CS9152**](#incorrect-interceptor-declaration): *Cannot intercept a call in file with this path because multiple files in the compilation have this path.*
98+
- [**CS9153**](#incorrect-interceptor-declaration): *The indicated call is intercepted multiple times.*
9999
- [**CS9155**](#signature-mismatch): *Cannot intercept call with `M` because it is not accessible within `V`.*
100100
- [**CS9156**](#signature-mismatch): *Cannot intercept call to `M` with `V` because of a difference in 'scoped' modifiers or `[UnscopedRef]` attributes.*
101101
- [**CS9157**](#incorrect-mapping): *Line and character numbers provided to `InterceptsLocationAttribute` must be positive.*
102-
- [**CS9160**](#other-failures): *A nameof operator cannot be intercepted.*
103-
- [**CS9161**](#other-failures): *An interceptor cannot be marked with `UnmanagedCallersOnlyAttribute`.*
102+
- [**CS9160**](#incorrect-interceptor-declaration): *A nameof operator cannot be intercepted.*
103+
- [**CS9161**](#incorrect-interceptor-declaration): *An interceptor cannot be marked with `UnmanagedCallersOnlyAttribute`.*
104104
- [**CS9177**](#signature-mismatch): *Interceptor must be non-generic or have matching arity.*
105105
- [**CS9178**](#signature-mismatch): *Method must be non-generic to match*
106-
- [**CS9206**](#other-failures): *An interceptor cannot be declared in the global namespace.*
107-
- [**CS9207**](#other-failures): *Cannot intercept because method is not an invocation of an ordinary member method.*
108-
- [**CS9231**](#interceptslocationattribute-errors): *The data argument to InterceptsLocationAttribute is not in the correct format.*
109-
- [**CS9232**](#interceptslocationattribute-errors): *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.*
110-
- [**CS9233**](#interceptslocationattribute-errors): *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.*
111-
- [**CS9234**](#interceptslocationattribute-errors): *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.*
112-
- [**CS9235**](#interceptslocationattribute-errors): *The data argument to InterceptsLocationAttribute refers to an invalid position in file 'file'.*
106+
- [**CS9206**](#incorrect-interceptor-declaration): *An interceptor cannot be declared in the global namespace.*
107+
- [**CS9207**](#incorrect-interceptor-declaration): *Cannot intercept because method is not an invocation of an ordinary member method.*
108+
- [**CS9231**](#incorrect-interceptor-declaration): *The data argument to InterceptsLocationAttribute is not in the correct format.*
109+
- [**CS9232**](#incorrect-interceptor-declaration): *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.*
110+
- [**CS9233**](#incorrect-interceptor-declaration): *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.*
111+
- [**CS9234**](#incorrect-interceptor-declaration): *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.*
112+
- [**CS9235**](#incorrect-interceptor-declaration): *The data argument to InterceptsLocationAttribute refers to an invalid position in file 'file'.*
113113

114114
The following warnings are generated when source generators or interceptors are loaded during a compilation:
115115

@@ -173,30 +173,15 @@ Interceptors require a source mapping that maps the interceptable method and the
173173
- **CS9150**: *Interceptor cannot have a `null` file path.*
174174
- **CS9157**: *Line and character numbers provided to `InterceptsLocationAttribute` must be positive.*
175175

176-
An interceptor specifies the location in the source code of the interceptable method. You specify the location by applying an `[InterceptsLocation]` attribute. You specify the line and column numbers in a remapped source file where the interceptor should be injected. These errors indicate that something in the attribute or the location doesn't match a location for a valid interceptable method. For details on the format and values for this attribute, see the [feature specification](https://github.com/dotnet/roslyn/blob/main/docs/features/interceptors.md#interceptslocationattribute).
176+
## Incorrect interceptor declaration
177177

178-
## InterceptsLocationAttribute errors
179-
180-
The following errors indicate issues with the `InterceptsLocationAttribute` format or the data provided to it:
178+
The following errors indicate issues with interceptor declarations, including problems with the `InterceptsLocationAttribute` format or violations of interceptor rules:
181179

182180
- **CS9231**: *The data argument to InterceptsLocationAttribute is not in the correct format.*
183181
- **CS9232**: *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.*
184182
- **CS9233**: *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.*
185183
- **CS9234**: *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.*
186184
- **CS9235**: *The data argument to InterceptsLocationAttribute refers to an invalid position in file 'file'.*
187-
188-
These errors occur when the `InterceptsLocationAttribute` contains invalid data:
189-
190-
- **CS9231** is generated when the data format doesn't match the expected structure. The attribute requires specifically formatted data that encodes the file path and position information.
191-
- **CS9232** indicates you're using a version number that isn't supported. The interceptors feature uses version '1' format. Update your source generator to use the supported version.
192-
- **CS9233** happens when the compilation contains multiple files with the same path, making it ambiguous which file to intercept in. Ensure each file in your compilation has a unique path.
193-
- **CS9234** is emitted when the file path specified in the attribute doesn't match any file in the current compilation. Verify the file path is correct and the file is included in the compilation.
194-
- **CS9235** occurs when the position data (line and character numbers) points to an invalid location in the specified file. This can happen if the position is outside the file's bounds or doesn't correspond to a valid interception point.
195-
196-
## Other failures
197-
198-
These errors indicate other limitations for interceptors:
199-
200185
- **CS9138**: *Method cannot be used as an interceptor because it or its containing type has type parameters.*
201186
- **CS9146**: *An interceptor method must be an ordinary member method.*
202187
- **CS9151**: *Possible method name `M` cannot be intercepted because it is not being invoked.*
@@ -207,12 +192,19 @@ These errors indicate other limitations for interceptors:
207192
- **CS9206**: *An interceptor cannot be declared in the global namespace.*
208193
- **CS9207**: *Cannot intercept because method is not an invocation of an ordinary member method.*
209194

210-
These errors indicate that your interceptor method violates one of the rules for interceptors:
195+
These errors occur when interceptor declarations violate the rules for interceptors or when the `InterceptsLocationAttribute` contains invalid data:
211196

212-
- Interceptors can't be generic methods, or members of generic classes.
213-
- Interceptors must be ordinary members. They can't be operators, instance or static constructors, or finalizers.
214-
- Interceptable methods must be ordinary members. They can't be operators, instance or static constructors, or finalizers, nor delegate invocations.
215-
- Interceptable methods that are never invoked can't be intercepted.
216-
- Interceptable methods can be intercepted at most once.
217-
- Interceptors can't be methods limited to unmanaged callers.
218-
- Interceptors must be contained in a namespace.
197+
- **CS9231** is generated when the data format doesn't match the expected structure. The attribute requires specifically formatted data that encodes the file path and position information.
198+
- **CS9232** indicates you're using a version number that isn't supported. The interceptors feature uses version '1' format. Update your source generator to use the supported version.
199+
- **CS9233** happens when the compilation contains multiple files with the same path, making it ambiguous which file to intercept in. Ensure each file in your compilation has a unique path.
200+
- **CS9234** is emitted when the file path specified in the attribute doesn't match any file in the current compilation. Verify the file path is correct and the file is included in the compilation.
201+
- **CS9235** occurs when the position data (line and character numbers) points to an invalid location in the specified file. This can happen if the position is outside the file's bounds or doesn't correspond to a valid interception point.
202+
- **CS9138** prevents generic methods or members of generic classes from being interceptors.
203+
- **CS9146** requires interceptors to be ordinary members (not operators, constructors, or finalizers).
204+
- **CS9151** prevents intercepting methods that are never invoked.
205+
- **CS9152** detects duplicate file paths in the compilation.
206+
- **CS9153** prevents multiple interceptions of the same call.
207+
- **CS9160** prevents intercepting `nameof` operators.
208+
- **CS9161** prevents interceptors from being marked with `UnmanagedCallersOnlyAttribute`.
209+
- **CS9206** requires interceptors to be contained in a namespace (not global).
210+
- **CS9207** requires interceptable methods to be ordinary member invocations.

0 commit comments

Comments
 (0)