diff --git a/.github/prompts/error-consolidation.md b/.github/prompts/error-consolidation.md index 863202d303297..c96c2f381d53d 100644 --- a/.github/prompts/error-consolidation.md +++ b/.github/prompts/error-consolidation.md @@ -12,8 +12,8 @@ Overall steps: We're going to work through a series of files consolidating errors and warnings. -- For the duration of this chat, all references to "destination file" refer to `async-await-errors.md. -- For the duration of this chat, all references to "the target theme" refer to errors and warnings related to `async` function declarations and `await` expressions. +- For the duration of this chat, all references to "destination file" refer to `attribute-usage-errors.md`. +- For the duration of this chat, all references to "the target theme" refer to errors and warnings related to declaring and using *attributes*. The destination file already contains a skeleton for the final output. @@ -21,7 +21,7 @@ For each source file I specify in this chat, you'll do the following tasks: - Add the contents of the source file to the destination.md file. - Include the source error code in the YML header for f1_keywords and helpviewer_keywords. - - Add an entry with an anchor for the error error code and its corresponding error message. + - Add an entry with an anchor for the error error code and its corresponding error message. The error message should be the verbatim compiler error message. - Add the contents of the source file as a new H2 in the destination file. - Add a redirection for the source file in the file .openpublishing.redirection.csharp.json. Make the destination point to destination file. Place the new entry in sorted order based on 'source_path_from_root'. - Update the TOC file: @@ -31,7 +31,7 @@ For each source file I specify in this chat, you'll do the following tasks: ## Search for other related articles that may be missed. -Search all files in the docs/csharp/language-reference/compiler-messages and the docs/csharp/misc folder for any other errors and warnings that involve the target theme. Give me a list to review for possible additional consolidation. Don't make any edits until the originating user approves. +First, let's find candidate source files. Search all files in the docs/csharp/language-reference/compiler-messages and the docs/csharp/misc folder for any other errors and warnings that involve the target theme. Give me a list to review for possible additional consolidation. Don't make any edits until the originating user approves. ## Final search in roslyn source @@ -46,7 +46,7 @@ To make sure you've found all related errors, we'll check the source. Look in ` I'll give you error codes one by one. For each, I want you to do the following: - Add the new error code to the front matter of the destination file, for both the `f1_keywords` and `helpview_keywords` table. -- Add the new error code and error message to the table at the top of the destination file. +- Add the new error code and error message to the table at the top of the destination file. The error message should be the verbatim text from the compiler - Add the new error code to the list of `displayName` elements in the TOC file entry for the destination file. - Remove the new error code from the front matter in the file `csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-errors.md` file. @@ -61,3 +61,8 @@ To do that, make a new H2 section for the theme. Remove all the H2s for the indi The list of errors at the top of the file should remain in numerical order, so it's easy for readers to scan. Each impacted error code should now have a link to the anchor tag for the new section. Repeat the list in the new section, but without the anchors, as shown in the highlighted text. Understand these instructions, then suggest a list of themes and the included error codes. I'll approve each theme before you begin editing. + +## Move from description to resolution + +Rework the highlighted section so the focus is on how to correct each error. This article doesn't need to explain the associated language feature. Instead, in each section, provide links to language reference or language specification material that explains the rules violated when these diagnostics appear. Add explanatory context after each correction (in parentheses with the error code). Provided brief reasons why each correction is needed. Use detailed, sentence-style explanations rather than brief imperative statements. For each recommendation put the affectived error codes in parentheses, and in **bold** style. Remove extensive examples. + diff --git a/.openpublishing.redirection.csharp.json b/.openpublishing.redirection.csharp.json index 15f9328c66834..a8867a28f0d8f 100644 --- a/.openpublishing.redirection.csharp.json +++ b/.openpublishing.redirection.csharp.json @@ -1717,6 +1717,10 @@ "source_path_from_root": "/docs/csharp/misc/cs0242.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/unsafe-code-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0243.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, { "source_path_from_root": "/docs/csharp/misc/cs0244.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/unsafe-code-errors" @@ -1793,6 +1797,22 @@ "source_path_from_root": "/docs/csharp/misc/cs0400.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/assembly-references" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0404.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0415.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0416.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0447.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, { "source_path_from_root": "/docs/csharp/misc/cs0431.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors" @@ -1929,6 +1949,26 @@ "source_path_from_root": "/docs/csharp/misc/cs0576.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0577.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0578.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0582.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0609.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0629.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, { "source_path_from_root": "/docs/csharp/misc/cs0591.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch" @@ -1949,6 +1989,10 @@ "source_path_from_root": "/docs/csharp/misc/cs0623.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0625.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, { "source_path_from_root": "/docs/csharp/misc/cs0631.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors" @@ -1957,10 +2001,38 @@ "source_path_from_root": "/docs/csharp/misc/cs0633.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0636.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0637.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0641.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0646.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, { "source_path_from_root": "/docs/csharp/misc/cs0643.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0653.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0657.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0658.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, { "source_path_from_root": "/docs/csharp/misc/cs0655.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch" @@ -1973,6 +2045,10 @@ "source_path_from_root": "/docs/csharp/misc/cs0674.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0685.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/attribute-usage-errors" + }, { "source_path_from_root": "/docs/csharp/misc/cs0687.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors" diff --git a/docs/csharp/language-reference/compiler-messages/attribute-usage-errors.md b/docs/csharp/language-reference/compiler-messages/attribute-usage-errors.md new file mode 100644 index 0000000000000..e2a01a4666199 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/attribute-usage-errors.md @@ -0,0 +1,182 @@ +--- +title: Resolve errors and warnings that involve attribute declaration and attribute use in your code. +description: These compiler errors and warnings indicate errors in attribute declarations, or attribute use in your code. +f1_keywords: + - "CS0243" + - "CS0404" + - "CS0415" + - "CS0416" + - "CS0447" + - "CS0577" + - "CS0578" + - "CS0582" + - "CS0609" + - "CS0625" + - "CS0629" + - "CS0636" + - "CS0637" + - "CS0641" + - "CS0646" + - "CS0653" + - "CS0657" + - "CS0658" + - "CS0685" + - "CS7014" + - "CS7046" + - "CS7047" + - "CS7067" + - "CS9331" +helpviewer_keywords: + - "CS0243" + - "CS0404" + - "CS0415" + - "CS0416" + - "CS0447" + - "CS0577" + - "CS0578" + - "CS0582" + - "CS0609" + - "CS0625" + - "CS0629" + - "CS0636" + - "CS0637" + - "CS0641" + - "CS0646" + - "CS0653" + - "CS0657" + - "CS0658" + - "CS0685" + - "CS7014" + - "CS7046" + - "CS7047" + - "CS7067" + - "CS9331" +ms.date: 11/11/2025 +ai-usage: ai-assisted +--- +# Resolve errors and warnings related to attribute declarations or attribute use in your code + +This article covers the following compiler errors: + + +- [**CS0243**](#conditional-attribute-usage): *The Conditional attribute is not valid on 'method' because it is an override method.* +- [**CS0404**](#attribute-class-requirements): *Attribute is not valid on this declaration type.* +- [**CS0415**](#predefined-attributes): *This attribute is valid only on an indexer that is not an explicit interface member declaration.* +- [**CS0416**](#attribute-arguments-and-parameters): *'type parameter': an attribute argument cannot use type parameters.* +- [**CS0447**](#attribute-arguments-and-parameters): *Attribute cannot be used with type arguments.* +- [**CS0577**](#conditional-attribute-usage): *The Conditional attribute is not valid because it is a constructor, destructor, operator, lambda expression, or explicit interface implementation.* +- [**CS0578**](#conditional-attribute-usage): *The Conditional attribute is not valid on 'function' because its return type is not void.* +- [**CS0582**](#conditional-attribute-usage): *The Conditional attribute is not valid on interface members.* +- [**CS0609**](#predefined-attributes): *Cannot set the attribute on an indexer marked override.* +- [**CS0625**](#predefined-attributes): *Instance field in types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute.* +- [**CS0629**](#conditional-attribute-usage): *Conditional member 'member' cannot implement interface member 'base class member' in type 'Type Name'.* +- [**CS0636**](#predefined-attributes): *The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit).* +- [**CS0637**](#predefined-attributes): *The FieldOffset attribute is not allowed on static or const fields.* +- [**CS0641**](#attribute-class-requirements): *This attribute is only valid on classes derived from System.Attribute`.* +- [**CS0646**](#predefined-attributes): *Cannot specify the DefaultMember attribute on a type containing an indexer.* +- [**CS0653**](#attribute-class-requirements): *Cannot apply attribute class 'class' because it is abstract.* +- [**CS0657**](#attribute-location-context): *Location is not a valid attribute location for this declaration. Valid attribute locations for this declaration are listed. All attributes in this block will be ignored.* +- [**CS0658**](#attribute-location-context): *Location is not a recognized attribute location. Valid attribute locations for this declaration are listed. All attributes in this block will be ignored.* +- [**CS0685**](#conditional-attribute-usage): *Conditional member 'member' cannot have an out parameter.* +- [**CS7014**](#attribute-location-context): *Attributes are not valid in this context.* +- [**CS7046**](#attribute-arguments-and-parameters): *Attribute parameter must be specified.* +- [**CS7047**](#attribute-arguments-and-parameters): *Attribute parameter 'parameter1' or 'parameter2' must be specified.* +- [**CS7067**](#attribute-arguments-and-parameters): *Attribute constructor parameter is optional, but no default parameter value was specified.* +- [**CS9331**](#predefined-attributes): *Attribute cannot be applied manually.* + +## Attribute arguments and parameters + +The following errors occur when you use attribute arguments or parameters incorrectly: + +- **CS0416**: *'type parameter': an attribute argument cannot use type parameters.* +- **CS0447**: *Attribute cannot be used with type arguments.* +- **CS7046**: *Attribute parameter must be specified.* +- **CS7047**: *Attribute parameter 'parameter1' or 'parameter2' must be specified.* +- **CS7067**: *Attribute constructor parameter is optional, but no default parameter value was specified.* + +To correct these errors, follow these rules. + +- Use compile-time constant values for attribute arguments instead of type parameters (**CS0416**). Attribute arguments must be evaluated at compile time. +- Don't use type arguments with attributes (**CS0447**). Type arguments aren't allowed in attribute usage. +- Provide all required attribute parameters when you apply the attribute (**CS7046**, **CS7047**). Check the attribute's constructor to see which parameters are mandatory. +- Specify default values for optional constructor parameters when you define custom attributes (**CS7067**). Use the syntax `parameterType parameterName = defaultValue` in the attribute constructor. + +For more information, see [Attributes](../../advanced-topics/reflection-and-attributes/index.md) and [Generics](../../fundamentals/types/generics.md). + +> [!NOTE] +> **CS0447** is no longer used in Roslyn. + +## Attribute class requirements + +The following errors occur when you define attribute classes that don't meet the required constraints: + +- **CS0404**: *Attribute is not valid on this declaration type.* +- **CS0641**: *This attribute is only valid on classes derived from System.Attribute`.* +- **CS0653**: *Cannot apply attribute class 'class' because it is abstract.* + +To correct these errors, follow these rules. + +- Apply attributes only to valid declaration types (**CS0404**). Check the attribute's `AttributeUsage` to see which targets are allowed. +- Remove the `abstract` modifier from attribute classes, or derive from a non-abstract attribute class (**CS0653**). Attributes must be instantiable. +- Apply only to classes that derive from `Attribute` (**CS0641**). This attribute controls how other attributes are used. + + For more information, see [Create custom attributes](../../advanced-topics/reflection-and-attributes/creating-custom-attributes.md). + +## Attribute location context + +The following errors occur when you apply attributes in invalid locations or with incorrect target specifiers: + +- **CS0657**: *Location is not a valid attribute location for this declaration. Valid attribute locations for this declaration are listed. All attributes in this block will be ignored.* +- **CS0658**: *Location is not a recognized attribute location. Valid attribute locations for this declaration are listed. All attributes in this block will be ignored.* +- **CS7014**: *Attributes are not valid in this context.* + +To correct these errors, follow these rules. For more information, see [Attribute Targets](../../advanced-topics/reflection-and-attributes/index.md#attribute-targets). + +- Use valid attribute target specifiers for the declaration (**CS0657**). Check the error message to see which targets are valid for the specific declaration. +- Remove invalid attribute target specifiers (**CS0658**). Valid specifiers include `assembly:`, `module:`, `type:`, `method:`, `property:`, `field:`, `event:`, `param:`, and `return:`. +- Move attributes to valid contexts (**CS7014**). Attributes can only be applied to program elements that support them, as defined by . +- Apply attributes at the appropriate scope level. Use `assembly:` or `module:` prefixes for assembly-level or module-level attributes. + +## Predefined attributes + +The following errors occur when you use specific predefined .NET attributes incorrectly: + +- **CS0415**: *This attribute is valid only on an indexer that is not an explicit interface member declaration.* +- **CS0609**: *Cannot set the attribute on an indexer marked override.* +- **CS0625**: *Instance field in types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute.* +- **CS0636**: *The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit).* +- **CS0637**: *The FieldOffset attribute is not allowed on static or const fields.* +- **CS0646**: *Cannot specify the DefaultMember attribute on a type containing an indexer.* +- **CS9331**: *Attribute cannot be applied manually.* + +To correct these errors, follow these rules. For more information, see [Indexers](../../programming-guide/indexers/index.md) and [Platform Invoke (P/Invoke)](../../../standard/native-interop/pinvoke.md). + +- Remove from explicit interface implementations (**CS0415**). Apply it only to public indexers. +- Remove `IndexerName` from indexers marked with `override` (**CS0609**). Override indexers inherit the name from the base class. +- Add to all instance fields in types with set to `LayoutKind.Explicit` (**CS0625**). Explicit layout requires explicit field positions. +- Apply `FieldOffset` only to types with `StructLayout(LayoutKind.Explicit)` (**CS0636**). Add the `StructLayout` attribute to the type declaration. +- Remove `FieldOffset` from `static` or `const` fields (**CS0637**). Explicit layout applies only to instance fields. +- Remove from types that contain indexers (**CS0646**). Indexers automatically define the default member. +- Replace compiler-generated attributes with the equivalent C# syntax (**CS9331**). Use language keywords instead of manually applying reserved attributes. + +## Conditional attribute usage + +The following errors occur when you apply the in ways that violate its usage restrictions: + +- **CS0243**: *The Conditional attribute is not valid on 'method' because it is an override method.* +- **CS0577**: *The Conditional attribute is not valid because it is a constructor, destructor, operator, lambda expression, or explicit interface implementation.* +- **CS0578**: *The Conditional attribute is not valid on 'function' because its return type is not void.* +- **CS0582**: *The Conditional attribute is not valid on interface members.* +- **CS0629**: *Conditional member 'member' cannot implement interface member 'base class member' in type 'Type Name'.* +- **CS0685**: *Conditional member 'member' cannot have an out parameter.* + +To correct these errors, follow these rules. For more information, see and [Attributes](../../advanced-topics/reflection-and-attributes/index.md). + +- Remove the `Conditional` attribute from [override](../keywords/override.md) methods, or remove the `override` keyword (**CS0243**). The compiler binds to the base method, not the override. +- Don't apply `Conditional` to constructors, [finalizers](../../programming-guide/classes-and-structs/finalizers.md), operators, lambda expressions, or explicit interface implementations (**CS0577**). These member types don't support conditional compilation. +- Change the method's return type to `void`, or remove the `Conditional` attribute (**CS0578**). Conditional methods must return `void` because calls may be compiled out. +- Remove the `Conditional` attribute from interface member declarations (**CS0582**). Interface members can't be conditional. +- Remove the `Conditional` attribute from interface member implementations (**CS0629**). Methods implementing interface members can't be conditional. +- Remove `out` parameters from conditional methods, or remove the `Conditional` attribute (**CS0685**). The `out` variable value would be undefined when the method call is compiled out. diff --git a/docs/csharp/language-reference/toc.yml b/docs/csharp/language-reference/toc.yml index 081e8b3c26050..ac5e564fed106 100644 --- a/docs/csharp/language-reference/toc.yml +++ b/docs/csharp/language-reference/toc.yml @@ -466,6 +466,12 @@ items: CS1024, CS1025, CS1027, CS1028, CS1029, CS1030, CS1032, CS1038, CS1040, CS1517, CS1560, CS1576, CS1578, CS1633, CS1634, CS1635, CS1691, CS1692, CS1694, CS1695, CS1696, CS1709, CS9297, CS9298, CS9299, CS9314 + - name: Attribute declaration and usage + href: ./compiler-messages/attribute-usage-errors.md + displayName: > + CS0243, CS0404, CS0415, CS0416, CS0447, CS0577, CS0578, CS0582, CS0609, CS0625, + CS0629, CS0636, CS0637, CS0641, CS0646, CS0653, CS0657, CS0658, CS0685, CS7014, + CS7046, CS7047, CS7067, CS9331 - name: Feature or version missing href: ./compiler-messages/feature-version-errors.md displayName: > @@ -507,7 +513,8 @@ items: href: ./compiler-messages/async-await-errors.md displayName: > async, await, - CS1983, CS1985, CS1986, CS1989, CS1991, CS1992, CS1994, CS1995, CS1996, CS1997, CS1998, CS4008, CS4009, CS4014, CS4032, CS4033, CS8892, CS9123, CS9330 + CS1983, CS1985, CS1986, CS1989, CS1991, CS1992, CS1994, CS1995, CS1996, CS1997, + CS1998, CS4008, CS4009, CS4014, CS4032, CS4033, CS8892, CS9123, CS9330 - name: Reference parameters href: ./compiler-messages/ref-modifiers-errors.md displayName: > @@ -923,8 +930,6 @@ items: href: ../misc/cs0239.md - name: CS0241 href: ../misc/cs0241.md - - name: CS0243 - href: ../misc/cs0243.md - name: CS0247 href: ../misc/cs0247.md - name: CS0249 @@ -985,8 +990,6 @@ items: href: ../misc/cs0401.md - name: CS0403 href: ../misc/cs0403.md - - name: CS0404 - href: ../misc/cs0404.md - name: CS0405 href: ../misc/cs0405.md - name: CS0406 @@ -1003,10 +1006,6 @@ items: href: ../misc/cs0412.md - name: CS0413 href: ./compiler-messages/cs0413.md - - name: CS0415 - href: ../misc/cs0415.md - - name: CS0416 - href: ../misc/cs0416.md - name: CS0417 href: ./compiler-messages/cs0417.md - name: CS0418 @@ -1041,8 +1040,6 @@ items: href: ./compiler-messages/cs0445.md - name: CS0446 href: ./compiler-messages/cs0446.md - - name: CS0447 - href: ../misc/cs0447.md - name: CS0449 href: ../misc/cs0449.md - name: CS0450 @@ -1161,14 +1158,8 @@ items: href: ../misc/cs0574.md - name: CS0575 href: ../misc/cs0575.md - - name: CS0577 - href: ../misc/cs0577.md - - name: CS0578 - href: ../misc/cs0578.md - name: CS0579 href: ./compiler-messages/cs0579.md - - name: CS0582 - href: ../misc/cs0582.md - name: CS0583 href: ../misc/cs0583.md - name: CS0584 @@ -1191,8 +1182,6 @@ items: href: ../misc/cs0596.md - name: CS0601 href: ../misc/cs0601.md - - name: CS0609 - href: ../misc/cs0609.md - name: CS0610 href: ../misc/cs0610.md - name: CS0616 @@ -1205,30 +1194,16 @@ items: href: ../misc/cs0621.md - name: CS0622 href: ../misc/cs0622.md - - name: CS0625 - href: ../misc/cs0625.md - - name: CS0629 - href: ../misc/cs0629.md - name: CS0635 href: ../misc/cs0635.md - - name: CS0636 - href: ../misc/cs0636.md - - name: CS0637 - href: ../misc/cs0637.md - - name: CS0641 - href: ../misc/cs0641.md - name: CS0644 href: ../misc/cs0644.md - name: CS0645 href: ../misc/cs0645.md - - name: CS0646 - href: ../misc/cs0646.md - name: CS0647 href: ../misc/cs0647.md - name: CS0648 href: ../misc/cs0648.md - - name: CS0653 - href: ../misc/cs0653.md - name: CS0656 href: ../misc/cs0656.md - name: CS0662 @@ -1257,8 +1232,6 @@ items: href: ../misc/cs0682.md - name: CS0683 href: ../misc/cs0683.md - - name: CS0685 - href: ../misc/cs0685.md - name: CS0686 href: ./compiler-messages/cs0686.md - name: CS0689 @@ -1905,10 +1878,6 @@ items: href: ../misc/cs0612.md - name: CS0626 href: ../misc/cs0626.md - - name: CS0657 - href: ../misc/cs0657.md - - name: CS0658 - href: ../misc/cs0658.md - name: CS0672 href: ../misc/cs0672.md - name: CS0684 diff --git a/docs/csharp/misc/cs0243.md b/docs/csharp/misc/cs0243.md deleted file mode 100644 index 334bfcceb35c1..0000000000000 --- a/docs/csharp/misc/cs0243.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -description: "Compiler Error CS0243" -title: "Compiler Error CS0243" -ms.date: 07/20/2015 -f1_keywords: - - "CS0243" -helpviewer_keywords: - - "CS0243" -ms.assetid: 2506e4cb-dc26-46b4-a58c-ab6bf1601144 ---- -# Compiler error CS0243 - -The Conditional attribute is not valid on 'method' because it is an override method - -The attribute is not allowed on a method that is marked with the [override](../language-reference/keywords/override.md) keyword. For more information, see [Knowing When to Use Override and New Keywords](../programming-guide/classes-and-structs/knowing-when-to-use-override-and-new-keywords.md). - -The compiler never binds to override methods. It only binds to the base method, and the common language runtime calls the override, as appropriate. - -The following code generates CS0243: - -```csharp -// CS0243.cs -// compile with: /target:library -public class MyClass -{ - public virtual void M() {} -} - -public class MyClass2 : MyClass -{ - [System.Diagnostics.ConditionalAttribute("MySymbol")] // CS0243 - // remove Conditional attribute or remove override keyword - public override void M() {} -} -``` diff --git a/docs/csharp/misc/cs0404.md b/docs/csharp/misc/cs0404.md deleted file mode 100644 index c92a29f46bdfe..0000000000000 --- a/docs/csharp/misc/cs0404.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -description: "Compiler Error CS0404" -title: "Compiler Error CS0404" -ms.date: 07/20/2015 -f1_keywords: - - "CS0404" -helpviewer_keywords: - - "CS0404" -ms.assetid: 60bef49e-e0b7-4e9e-aab3-7afc20a19cb8 ---- -# Compiler Error CS0404 - -'<' unexpected : attributes cannot be generic - - Generic type parameters are not allowed in attributes. Remove the type parameter and angled brackets. - - The following sample generates CS0404: - -```csharp -// CS0404.cs -[MyAttrib] // CS0404 -class C -{ - public static void Main() - { - - } -} -``` diff --git a/docs/csharp/misc/cs0415.md b/docs/csharp/misc/cs0415.md deleted file mode 100644 index df0286bc8871e..0000000000000 --- a/docs/csharp/misc/cs0415.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -description: "Compiler Error CS0415" -title: "Compiler Error CS0415" -ms.date: 07/20/2015 -f1_keywords: - - "CS0415" -helpviewer_keywords: - - "CS0415" -ms.assetid: 1ed45b02-4568-4af4-b2a6-c8b01230d19a ---- -# Compiler Error CS0415 - -The 'IndexerName' attribute is valid only on an indexer that is not an explicit interface member declaration - - This error occurs if you use an IndexerName attribute on an indexer that was an explicit implementation of an interface. This error may be avoided by removing the interface name from the declaration of the indexer, if possible. For more information, see the [IndexerNameAttribute Class](xref:System.Runtime.CompilerServices.IndexerNameAttribute). - - The following sample generates CS0415: - -```csharp -// CS0415.cs -using System; -using System.Runtime.CompilerServices; - -public interface IA -{ - int this[int index] - { - get; - set; - } -} - -public class A : IA -{ - [IndexerName("Item")] // CS0415 - int IA.this[int index] - // Try this line instead: - // public int this[int index] - { - get { return 0; } - set { } - } - - static void Main() - { - } -} -``` diff --git a/docs/csharp/misc/cs0416.md b/docs/csharp/misc/cs0416.md deleted file mode 100644 index f2fd0c9d1c787..0000000000000 --- a/docs/csharp/misc/cs0416.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -description: "Compiler Error CS0416" -title: "Compiler Error CS0416" -ms.date: 07/20/2015 -f1_keywords: - - "CS0416" -helpviewer_keywords: - - "CS0416" -ms.assetid: 61bfe40d-5e87-47e5-933f-3491e28ace42 ---- -# Compiler Error CS0416 - -'type parameter': an attribute argument cannot use type parameters - - A type parameter was used as an attribute argument, which is not allowed. Use a non-generic type. - - The following sample generates CS0416: - -```csharp -// CS0416.cs -public class MyAttribute : System.Attribute -{ - public MyAttribute(System.Type t) - { - } -} - -class G -{ - - [MyAttribute(typeof(G))] // CS0416 - public void F() - { - } - -} -``` diff --git a/docs/csharp/misc/cs0447.md b/docs/csharp/misc/cs0447.md deleted file mode 100644 index 5a8e47c84f282..0000000000000 --- a/docs/csharp/misc/cs0447.md +++ /dev/null @@ -1,49 +0,0 @@ ---- -description: "Compiler Error CS0447" -title: "Compiler Error CS0447" -ms.date: 07/20/2015 -f1_keywords: - - "CS0447" -helpviewer_keywords: - - "CS0447" -ms.assetid: a25486c5-e9bf-4528-8533-c1aaab22ace0 ---- -# Compiler Error CS0447 - -Attributes cannot be used on type arguments, only on type parameters - -This error occurs when you apply an attribute to a type argument that occurs in an invocation statement. It is acceptable to apply an attribute to a type parameter in a class or method declaration statement such as the following: - -```csharp -class C<[some attribute] T> {…} -``` - -The following line of code will generate this error. It is assumed that the class `C`, defined in the previous line of code, has a static method called `MyStaticMethod`. - -```csharp -C<[some attribute] T>.MyStaticMethod(); -``` - -## Example - -The following code generates error CS0447: - -```csharp -// CS0447.cs -using System; - -namespace Test41 -{ - public interface I - { - void Meth(); - } - public class B : I - { - void I<[Test] int>.Meth() { } // CS0447 - } -} -``` - -> [!NOTE] -> This compiler error is no longer used in Roslyn. diff --git a/docs/csharp/misc/cs0577.md b/docs/csharp/misc/cs0577.md deleted file mode 100644 index 099127a50c2ea..0000000000000 --- a/docs/csharp/misc/cs0577.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -description: "Compiler Error CS0577" -title: "Compiler Error CS0577" -ms.date: 07/20/2015 -f1_keywords: - - "CS0577" -helpviewer_keywords: - - "CS0577" -ms.assetid: 34f8f453-f016-4f2c-981a-0d61449cd74b ---- -# Compiler Error CS0577 - -The Conditional attribute is not valid on 'function' because it is a constructor, destructor, operator, or explicit interface implementation - -> [!NOTE] -> Destructor is a deprecated term for [finalizer](../programming-guide/classes-and-structs/finalizers.md). - - `Conditional` cannot be applied to the specified methods. - - For example, you cannot use some attributes on an explicit interface definition. The following sample generates CS0577: - -```csharp -// CS0577.cs -// compile with: /target:library -interface I -{ - void m(); -} - -public class MyClass : I -{ - [System.Diagnostics.Conditional("a")] // CS0577 - void I.m() {} -} -``` diff --git a/docs/csharp/misc/cs0578.md b/docs/csharp/misc/cs0578.md deleted file mode 100644 index 58ef92adcdf2e..0000000000000 --- a/docs/csharp/misc/cs0578.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -description: "Compiler Error CS0578" -title: "Compiler Error CS0578" -ms.date: 07/20/2015 -f1_keywords: - - "CS0578" -helpviewer_keywords: - - "CS0578" -ms.assetid: fbc5c884-e358-48f1-aeac-5ec8fd9f0c40 ---- -# Compiler Error CS0578 - -The Conditional attribute is not valid on 'function' because its return type is not void - - cannot be applied to a method that has a return type other than `void`. The reason for this is that any other return type for a method may be needed by another part of your program. - -## Example - -The following sample generates CS0578. To resolve this error, you must either delete , or you must change the return value of the method to `void`. - -```csharp -// CS0578.cs -// compile with: /target:library -public class MyClass -{ - [System.Diagnostics.ConditionalAttribute("a")] // CS0578 - public int TestMethod() - { - return 0; - } -} -``` diff --git a/docs/csharp/misc/cs0582.md b/docs/csharp/misc/cs0582.md deleted file mode 100644 index 9d3ad889e36a5..0000000000000 --- a/docs/csharp/misc/cs0582.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -description: "Compiler Error CS0582" -title: "Compiler Error CS0582" -ms.date: 07/20/2015 -f1_keywords: - - "CS0582" -helpviewer_keywords: - - "CS0582" -ms.assetid: cc0f4c75-c41d-423e-a4dc-e55a124f5cae ---- -# Compiler Error CS0582 - -The Conditional not valid on interface members - - **ConditionalAttribute** is not valid on an interface member. - - The following sample generates CS0582: - -```csharp -// CS0582.cs -// compile with: /target:library -using System.Diagnostics; -interface MyIFace -{ - [ConditionalAttribute("DEBUG")] // CS0582 - void zz(); -} -``` diff --git a/docs/csharp/misc/cs0609.md b/docs/csharp/misc/cs0609.md deleted file mode 100644 index 7d90c4c7a71ad..0000000000000 --- a/docs/csharp/misc/cs0609.md +++ /dev/null @@ -1,62 +0,0 @@ ---- -description: "Compiler Error CS0609" -title: "Compiler Error CS0609" -ms.date: 07/20/2015 -f1_keywords: - - "CS0609" -helpviewer_keywords: - - "CS0609" -ms.assetid: f3ff07a6-1190-4a1c-86a5-f607e1a32b78 ---- -# Compiler Error CS0609 - -Cannot set the IndexerName attribute on an indexer marked override - - The name attribute (**IndexerNameAttribute**) cannot be applied to an indexed property that is an override. For more information, see [Indexers](../programming-guide/indexers/index.md). - - The following sample generates CS0609: - -```csharp -// CS0609.cs -using System; -using System.Runtime.CompilerServices; - -public class idx -{ - public virtual int this[int iPropIndex] - { - get - { - return 0; - } - set - { - } - } -} - -public class MonthDays : idx -{ - [IndexerName("MonthInfoIndexer")] // CS0609, delete to resolve this CS0609 - public override int this[int iPropIndex] - { - get - { - return 0; - } - set - { - } - } -} - -public class test -{ - public static void Main(string[] args) - { - } -} -``` - -> [!NOTE] -> This compiler error is no longer used in Roslyn. The previous code should compile successfully. diff --git a/docs/csharp/misc/cs0625.md b/docs/csharp/misc/cs0625.md deleted file mode 100644 index 0ca54e2748e6c..0000000000000 --- a/docs/csharp/misc/cs0625.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -description: "Compiler Error CS0625" -title: "Compiler Error CS0625" -ms.date: 07/20/2015 -f1_keywords: - - "CS0625" -helpviewer_keywords: - - "CS0625" -ms.assetid: 44091813-9988-436c-b35e-e24094793782 ---- -# Compiler Error CS0625 - -'field': instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute. - -When a struct is marked with an explicit **StructLayout** attribute, all fields in the struct must have the [FieldOffset](xref:System.Runtime.InteropServices.FieldOffsetAttribute) attribute. For more information, see [StructLayoutAttribute Class](xref:System.Runtime.InteropServices.StructLayoutAttribute). - -The following sample generates CS0625: - -```csharp -// CS0625.cs -// compile with: /target:library -using System; -using System.Runtime.InteropServices; - -[StructLayout(LayoutKind.Explicit)] -struct A -{ - public int i; // CS0625 not static; an instance field -} - -// OK -[StructLayout(LayoutKind.Explicit)] -struct B -{ - [FieldOffset(5)] - public int i; -} -``` diff --git a/docs/csharp/misc/cs0629.md b/docs/csharp/misc/cs0629.md deleted file mode 100644 index 81921230ccba0..0000000000000 --- a/docs/csharp/misc/cs0629.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -description: "Compiler Error CS0629" -title: "Compiler Error CS0629" -ms.date: 07/20/2015 -f1_keywords: - - "CS0629" -helpviewer_keywords: - - "CS0629" -ms.assetid: 20f22ef0-3c6f-4108-ab09-3f0752375a10 ---- -# Compiler error CS0629 - -Conditional member 'member' cannot implement interface member 'base class member' in type 'Type Name' - -The [Conditional attribute](../language-reference/attributes/general.md#conditional-attribute) cannot be used on the implementation of an interface. - -The following sample generates CS0629: - -```csharp -// CS0629.cs -interface MyInterface -{ - void MyMethod(); -} - -public class MyClass : MyInterface -{ - [System.Diagnostics.Conditional("debug")] - public void MyMethod() // CS0629, remove the Conditional attribute - { - } - - public static void Main() - { - } -} -``` diff --git a/docs/csharp/misc/cs0636.md b/docs/csharp/misc/cs0636.md deleted file mode 100644 index d2cd0bad44b93..0000000000000 --- a/docs/csharp/misc/cs0636.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -description: "Compiler Error CS0636" -title: "Compiler Error CS0636" -ms.date: 07/20/2015 -f1_keywords: - - "CS0636" -helpviewer_keywords: - - "CS0636" -ms.assetid: 47597f89-fbe6-4708-9493-3c86c6f0ce56 ---- -# Compiler Error CS0636 - -The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit) - - You must use the **StructLayout(LayoutKind.Explicit)** attribute on the struct declaration, if it contains any members marked with the **FieldOffset** attribute. For more information, see [FieldOffset](xref:System.Runtime.InteropServices.FieldOffsetAttribute). - - The following sample generates CS0636: - -```csharp -// CS0636.cs -using System; -using System.Runtime.InteropServices; - -// To resolve the error, uncomment the following line: -// [StructLayout(LayoutKind.Explicit)] -struct Worksheet -{ - [FieldOffset(4)]public int i; // CS0636 -} - -public class MainClass -{ - public static void Main () - { - } -} -``` diff --git a/docs/csharp/misc/cs0637.md b/docs/csharp/misc/cs0637.md deleted file mode 100644 index 09981850c9af7..0000000000000 --- a/docs/csharp/misc/cs0637.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -description: "Compiler Error CS0637" -title: "Compiler Error CS0637" -ms.date: 07/20/2015 -f1_keywords: - - "CS0637" -helpviewer_keywords: - - "CS0637" -ms.assetid: 02f6964c-0fcc-4f81-8ebb-0330aecdde19 ---- -# Compiler Error CS0637 - -The FieldOffset attribute is not allowed on static or const fields. - - The [FieldOffset](xref:System.Runtime.InteropServices.FieldOffsetAttribute) attribute cannot be used on fields marked with [static](../language-reference/keywords/static.md) or [const](../language-reference/keywords/const.md). - - The following sample generates CS0637: - -```csharp -// CS0637.cs -using System; -using System.Runtime.InteropServices; - -[StructLayout(LayoutKind.Explicit)] -public class MainClass -{ - [FieldOffset(3)] // CS0637 - public static int i; - public static void Main () - { - } -} -``` diff --git a/docs/csharp/misc/cs0641.md b/docs/csharp/misc/cs0641.md deleted file mode 100644 index 0513d688a7409..0000000000000 --- a/docs/csharp/misc/cs0641.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -description: "Compiler Error CS0641" -title: "Compiler Error CS0641" -ms.date: 07/20/2015 -f1_keywords: - - "CS0641" -helpviewer_keywords: - - "CS0641" -ms.assetid: 5bcdb11a-fefd-4c71-9b31-4c4f719633f3 ---- -# Compiler Error CS0641 - -'attribute' : attribute is only valid on classes derived from System.Attribute - - An attribute was used that can only be used on a class that derives from **System.Attribute**. - - The following sample generates CS0641: - -```csharp -// CS0641.cs -using System; - -[AttributeUsage(AttributeTargets.All)] -public class NonAttrClass // CS0641 -// try the following line instead -// public class NonAttrClass : Attribute -{ -} - -class MyClass -{ - public static void Main() - { - } -} -``` diff --git a/docs/csharp/misc/cs0646.md b/docs/csharp/misc/cs0646.md deleted file mode 100644 index e715835aa12c5..0000000000000 --- a/docs/csharp/misc/cs0646.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -description: "Compiler Error CS0646" -title: "Compiler Error CS0646" -ms.date: 07/20/2015 -f1_keywords: - - "CS0646" -helpviewer_keywords: - - "CS0646" -ms.assetid: 48ea306f-b4a0-4988-8d2b-ca9d38e9bdad ---- -# Compiler Error CS0646 - -Cannot specify the DefaultMember attribute on a type containing an indexer - - If a class or other type specifies **System.Reflection.DefaultMemberAttribute**, it cannot contain an indexer. For more information, see [Properties](../programming-guide/classes-and-structs/properties.md). - - The following sample generates CS0646: - -```csharp -// CS0646.cs -// compile with: /target:library -[System.Reflection.DefaultMemberAttribute("x")] // CS0646 -class MyClass -{ - public int this[int index] // an indexer - { - get - { - return 0; - } - } - - public int x = 0; -} - -// OK -[System.Reflection.DefaultMemberAttribute("x")] -class MyClass2 -{ - public int prop - { - get - { - return 0; - } - } - - public int x = 0; -} - -class MyClass3 -{ - public int this[int index] // an indexer - { - get - { - return 0; - } - } - - public int x = 0; -} -``` diff --git a/docs/csharp/misc/cs0653.md b/docs/csharp/misc/cs0653.md deleted file mode 100644 index da78e17fff1c0..0000000000000 --- a/docs/csharp/misc/cs0653.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -description: "Compiler Error CS0653" -title: "Compiler Error CS0653" -ms.date: 07/20/2015 -f1_keywords: - - "CS0653" -helpviewer_keywords: - - "CS0653" -ms.assetid: c94043b9-b5d9-4294-921d-a4aead124d44 ---- -# Compiler Error CS0653 - -Cannot apply attribute class 'class' because it is abstract - - An [abstract](../language-reference/keywords/abstract.md) custom attribute class cannot be used as an attribute. - - The following sample generates CS0653: - -```csharp -// CS0653.cs -using System; - -public abstract class MyAttribute : Attribute -{ -} - -public class My2Attribute : MyAttribute -{ -} - -[My] // CS0653 -// try the following line instead -// [My2] -class MyClass -{ - public static void Main() - { - } -} -``` diff --git a/docs/csharp/misc/cs0657.md b/docs/csharp/misc/cs0657.md deleted file mode 100644 index 5e8fa8db48d07..0000000000000 --- a/docs/csharp/misc/cs0657.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -description: "Compiler Warning (level 1) CS0657" -title: "Compiler Warning (level 1) CS0657" -ms.date: 07/20/2015 -f1_keywords: - - "CS0657" -helpviewer_keywords: - - "CS0657" -ms.assetid: d12d2efc-f44e-40e6-b825-5a66ead0c08e ---- -# Compiler Warning (level 1) CS0657 - -'attribute modifier' is not a valid attribute location for this declaration. Valid attribute locations for this declaration are 'locations'. All attributes in this block will be ignored. - - The compiler found an attribute modifier in an invalid location. See [Attribute Targets](/dotnet/csharp/advanced-topics/reflection-and-attributes#attribute-targets) for more information. - - The following sample generates CS0657: - -```csharp -// CS0657.cs -// compile with: /target:library -public class TestAttribute : System.Attribute {} -[return: Test] // CS0657 return not valid on a class -class Class1 {} -``` diff --git a/docs/csharp/misc/cs0658.md b/docs/csharp/misc/cs0658.md deleted file mode 100644 index ef34d72c2451c..0000000000000 --- a/docs/csharp/misc/cs0658.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -description: "Compiler Warning (level 1) CS0658" -title: "Compiler Warning (level 1) CS0658" -ms.date: 07/20/2015 -f1_keywords: - - "CS0658" -helpviewer_keywords: - - "CS0658" -ms.assetid: 0309074c-741a-492c-9370-73b4bbfd3c1a ---- -# Compiler Warning (level 1) CS0658 - -'attribute modifier' is not a recognized attribute location. All attributes in this block will be ignored. - - An invalid attribute modifier was specified. See [Attribute Targets](/dotnet/csharp/advanced-topics/reflection-and-attributes#attribute-targets) for more information. - - The following sample generates CS0658: - -```csharp -// CS0658.cs -using System; -public class TestAttribute : Attribute {} -[badAttributeLocation: Test] // CS0658, badAttributeLocation is invalid -class ClassTest -{ - public static void Main() - { - } -} -``` diff --git a/docs/csharp/misc/cs0685.md b/docs/csharp/misc/cs0685.md deleted file mode 100644 index 655356e48c18e..0000000000000 --- a/docs/csharp/misc/cs0685.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -description: "Compiler Error CS0685" -title: "Compiler Error CS0685" -ms.date: 07/20/2015 -f1_keywords: - - "CS0685" -helpviewer_keywords: - - "CS0685" -ms.assetid: 20d7c6cf-a388-430f-b22b-232536912491 ---- -# Compiler Error CS0685 - -Conditional member 'member' cannot have an out parameter - - When using the attribute on a method, that method may not have an out parameter. This is because the value of the variable used for the out parameter would not be defined in the case that the method call is compiled to nothing. To avoid this error, remove the out parameter from the conditional method declaration, or don't use the Conditional Attribute. - -## Example - - The following sample generates CS0685: - -```csharp -// CS0685.cs -using System.Diagnostics; - -class C -{ - [Conditional("DEBUG")] - void trace(out int i) // CS0685 - { - i = 1; - } -} -``` diff --git a/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md b/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md index bc74762b1800a..7a25597850dd4 100644 --- a/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md +++ b/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md @@ -82,7 +82,6 @@ f1_keywords: - "CS7006" - "CS7012" - "CS7013" - - "CS7014" - "CS7015" - "CS7016" - "CS7017" @@ -107,8 +106,6 @@ f1_keywords: - "CS7042" - "CS7043" - "CS7045" - - "CS7046" - - "CS7047" - "CS7048" - "CS7049" - "CS7050" @@ -124,7 +121,6 @@ f1_keywords: - "CS7064" - "CS7065" - "CS7066" - - "CS7067" - "CS7070" - "CS7080" - "CS7081" @@ -542,8 +538,6 @@ f1_keywords: - "CS9096" - "CS9097" # C# 14 errors begin here - - - "CS9331" - "CS9333" - "CS9334" - "CS9338"