You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/compiler-messages/source-generator-errors.md
+31-39Lines changed: 31 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,36 +80,36 @@ ms.date: 05/23/2025
80
80
The following errors are generated when source generators or interceptors are loaded during a compilation:
81
81
82
82
-[**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.*
84
84
-[**CS9139**](#incorrect-mapping): *Cannot intercept: compilation does not contain a file with path.*
85
85
-[**CS9140**](#incorrect-mapping): *Cannot intercept: compilation does not contain a file with path. Did you mean to use a different path?*
86
86
-[**CS9141**](#incorrect-mapping): *The provided line and character number does not refer to an interceptable method name, but rather to a token.*
87
87
-[**CS9142**](#incorrect-mapping): *The given file has `n` lines, which is fewer than the provided line number `m`.*
88
88
-[**CS9143**](#incorrect-mapping): *The given line is `c` characters long, which is fewer than the provided character number `n`.*
89
89
-[**CS9144**](#signature-mismatch): *Cannot intercept method `M` with interceptor `V` because the signatures do not match.*
90
90
-[**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.*
92
92
-[**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`?*
93
93
-[**CS9148**](#signature-mismatch): *Interceptor must have a `this` parameter matching parameter.*
94
94
-[**CS9149**](#signature-mismatch): *Interceptor must not have a `this` parameter because method does not have a `this` parameter.*
95
95
-[**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.*
99
99
-[**CS9155**](#signature-mismatch): *Cannot intercept call with `M` because it is not accessible within `V`.*
100
100
-[**CS9156**](#signature-mismatch): *Cannot intercept call to `M` with `V` because of a difference in 'scoped' modifiers or `[UnscopedRef]` attributes.*
101
101
-[**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`.*
104
104
-[**CS9177**](#signature-mismatch): *Interceptor must be non-generic or have matching arity.*
105
105
-[**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'.*
113
113
114
114
The following warnings are generated when source generators or interceptors are loaded during a compilation:
115
115
@@ -173,30 +173,15 @@ Interceptors require a source mapping that maps the interceptable method and the
173
173
-**CS9150**: *Interceptor cannot have a `null` file path.*
174
174
-**CS9157**: *Line and character numbers provided to `InterceptsLocationAttribute` must be positive.*
175
175
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
177
177
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:
181
179
182
180
-**CS9231**: *The data argument to InterceptsLocationAttribute is not in the correct format.*
183
181
-**CS9232**: *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.*
184
182
-**CS9233**: *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.*
185
183
-**CS9234**: *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.*
186
184
-**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
-
200
185
-**CS9138**: *Method cannot be used as an interceptor because it or its containing type has type parameters.*
201
186
-**CS9146**: *An interceptor method must be an ordinary member method.*
202
187
-**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:
207
192
-**CS9206**: *An interceptor cannot be declared in the global namespace.*
208
193
-**CS9207**: *Cannot intercept because method is not an invocation of an ordinary member method.*
209
194
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:
211
196
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.
0 commit comments