Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .openpublishing.redirection.csharp.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,34 @@
"source_path_from_root": "/docs/csharp/fundamentals/types/namespaces.md",
"redirect_url": "/dotnet/csharp/fundamentals/program-structure/namespaces"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0006.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0007.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs0016.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1564.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1616.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1763.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/generic-type-parameters-errors"
},
{
"source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs2032.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/misc/cs0017.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/entry-point-errors"
Expand Down Expand Up @@ -336,10 +360,18 @@
"source_path_from_root": "/docs/csharp/misc/cs1638.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/feature-version-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1668.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1715.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/property-declaration-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1719.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/misc/cs1720.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/generic-type-parameters-errors"
Expand All @@ -352,10 +384,34 @@
"source_path_from_root": "/docs/csharp/misc/cs1958.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/delegate-function-pointer-diagnostics"
},
{
"source_path_from_root": "/docs/csharp/misc/cs2008.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/misc/cs2017.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/entry-point-errors"
},
{
"source_path_from_root": "/docs/csharp/misc/cs2019.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/misc/cs2029.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/misc/cs2036.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/misc/cs3012.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/misc/cs3013.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/invalid-build-command-line"
},
{
"source_path_from_root": "/docs/csharp/misc/cs3024.md",
"redirect_url": "/dotnet/csharp/language-reference/compiler-messages/generic-type-parameters-errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ f1_keywords:
- "CS8962"
- "CS8963"
- "CS8968"
- "CS8783"
- "CS8970"
- "CS9331"
helpviewer_keywords:
Expand Down Expand Up @@ -89,9 +90,10 @@ helpviewer_keywords:
- "CS8962"
- "CS8963"
- "CS8968"
- "CS8783"
- "CS8970"
- "CS9331"
ms.date: 02/13/2026
ms.date: 05/19/2026
ai-usage: ai-assisted
---
# Resolve errors and warnings related to attribute declarations or attribute use in your code
Expand Down Expand Up @@ -143,6 +145,7 @@ That's by design. The text closely matches the text of the compiler error / warn
- [**CS8962**](#callerargumentexpression-attribute-usage): *The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is overridden by the CallerMemberNameAttribute.*
- [**CS8963**](#callerargumentexpression-attribute-usage): *The CallerArgumentExpressionAttribute applied to parameter will have no effect. It is applied with an invalid parameter name.*
- [**CS8968**](#attribute-arguments-and-parameters): *An attribute type argument cannot use type parameters*
- [**CS8783**](#conditional-attribute-usage): *Local function 'method' must be 'static' in order to use the Conditional attribute*
- [**CS8970**](#attribute-arguments-and-parameters): *Type cannot be used in this context because it cannot be represented in metadata.*
- [**CS9331**](#predefined-attributes): *Attribute cannot be applied manually.*

Expand Down Expand Up @@ -234,16 +237,16 @@ The following errors occur when you use specific predefined .NET attributes inco

To correct these errors, follow these rules. For more information, see [Indexers](../../programming-guide/indexers/index.md), [Structure types](../builtin-types/struct.md), <xref:System.Runtime.CompilerServices.TypeForwardedToAttribute>, and [Platform Invoke (P/Invoke)](../../../standard/native-interop/pinvoke.md).

- The <xref:System.Runtime.CompilerServices.IndexerNameAttribute> can only be applied to indexers that aren't explicit interface member declarations (**CS0415**). Remove the attribute from explicit interface indexers, because the interface already defines the indexer name.
- You can apply <xref:System.Runtime.CompilerServices.IndexerNameAttribute> only to indexers that aren't explicit interface member declarations (**CS0415**). Remove the attribute from explicit interface indexers, because the interface already defines the indexer name.
- You can't apply `IndexerName` to indexers marked with `override` because override indexers inherit their name from the base class (**CS0609**). Remove the `IndexerName` attribute from the override indexer.
- Every instance field in a type marked with `StructLayout(LayoutKind.Explicit)` must have a <xref:System.Runtime.InteropServices.FieldOffsetAttribute> (**CS0625**). Explicit layout requires that you specify the byte offset for each instance field.
- The <xref:System.Runtime.InteropServices.FieldOffsetAttribute> can only be placed on members of types that have <xref:System.Runtime.InteropServices.StructLayoutAttribute> set to `LayoutKind.Explicit` (**CS0636**). Add the `StructLayout` attribute to the containing type declaration.
- You can place the <xref:System.Runtime.InteropServices.FieldOffsetAttribute> only on members of types that have <xref:System.Runtime.InteropServices.StructLayoutAttribute> set to `LayoutKind.Explicit` (**CS0636**). Add the `StructLayout` attribute to the containing type declaration.
- The `FieldOffset` attribute isn't allowed on `static` or `const` fields because explicit layout applies only to instance fields (**CS0637**). Remove the `FieldOffset` attribute from the static or const field.
- You can't apply <xref:System.Reflection.DefaultMemberAttribute> to a type that already contains an indexer because the compiler automatically defines the default member for types with indexers (**CS0646**). Remove the `DefaultMember` attribute.
- All <xref:System.Runtime.CompilerServices.IndexerNameAttribute> attributes within a type must specify the same name (**CS0668**). Change the names to match, because the runtime uses a single name for all indexers on a type.
- The type specified as an argument for <xref:System.Runtime.CompilerServices.TypeForwardedToAttribute> must be a non-generic, non-nested, non-pointer, non-array type (**CS0735**). Only top-level named types are valid forwarding targets.
- You must specify a non-generic, non-nested, non-pointer, non-array type as an argument for <xref:System.Runtime.CompilerServices.TypeForwardedToAttribute> (**CS0735**). Only top-level named types are valid forwarding targets.
- An assembly can have only one <xref:System.Runtime.CompilerServices.TypeForwardedToAttribute> for each external type (**CS0739**). Locate and remove the duplicate `TypeForwardedTo` declaration.
- The <xref:System.Runtime.CompilerServices.RequiredAttributeAttribute> isn't permitted on types defined in C# (**CS1608**). This attribute is reserved for other languages that need to force compilers to require a particular feature.
- You can't use the <xref:System.Runtime.CompilerServices.RequiredAttributeAttribute> on types defined in C# (**CS1608**). This attribute is reserved for other languages that need to force compilers to require a particular feature.
- Some attributes are reserved for the compiler and can't be applied manually in source code (**CS9331**). Replace the attribute with the equivalent C# language syntax that causes the compiler to generate it.

## Conditional attribute usage
Expand All @@ -258,6 +261,7 @@ You see the following errors when you apply the <xref:System.Diagnostics.Conditi
- **CS0685**: *Conditional member 'member' cannot have an out parameter.*
- **CS1618**: *Cannot create delegate with method because it or a method it overrides has a Conditional attribute*
- **CS1689**: *Attribute is only valid on methods or attribute classes*
- **CS8783**: *Local function 'method' must be 'static' in order to use the Conditional attribute*

To correct these errors, follow these rules. For more information, see <xref:System.Diagnostics.ConditionalAttribute>, [Conditional methods](~/_csharpstandard/standard/attributes.md#23532-conditional-methods), and [Attributes](../../advanced-topics/reflection-and-attributes/index.md).

Expand All @@ -269,6 +273,7 @@ To correct these errors, follow these rules. For more information, see <xref:Sys
- Conditional methods can't have `out` parameters because the `out` variable value would be undefined when the compiler omits the method call (**CS0685**). Remove the `out` parameters from the method, or remove the `Conditional` attribute.
- You can't create a delegate that references a conditional method because the method might not exist in builds where the condition symbol isn't defined (**CS1618**). Remove the `Conditional` attribute from the method, or don't use it as a delegate target.
- The `Conditional` attribute is only valid on methods and attribute classes (**CS1689**). It isn't valid on other declaration types such as non-attribute classes, structs, or interfaces.
- A local function must be declared `static` to use the `Conditional` attribute (**CS8783**). Non-static local functions capture state from the enclosing method, and the compiler can't safely omit a call that might involve captured variables. Add the `static` modifier to the local function, or remove the `[Conditional]` attribute.

## CallerArgumentExpression attribute usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ f1_keywords:
- "CS1018" # ERR_ThisOrBaseExpected
- "CS8054" # ERR_EnumsCantContainDefaultConstructor
- "CS8091" # ERR_ExternHasConstructorInitializer
- "CS8760" # ERR_ExternEventInitializer
- "CS8358" # ERR_AttributeCtorInParameter
- "CS8813" # ERR_ModuleInitializerMethodMustBeOrdinary
- "CS8814" # ERR_ModuleInitializerMethodMustBeAccessibleOutsideTopLevelType
Expand Down Expand Up @@ -78,6 +79,7 @@ helpviewer_keywords:
- "CS8054"
- "CS8091"
- "CS8358"
- "CS8760"
- "CS8813"
- "CS8814"
- "CS8815"
Expand Down Expand Up @@ -120,7 +122,7 @@ helpviewer_keywords:
- "CS9124"
- "CS9136"
- "CS9179"
ms.date: 05/01/2026
ms.date: 05/19/2026
---
# Resolve errors and warnings for constructor declarations and module initializers

Expand All @@ -143,6 +145,7 @@ That's by design. The text closely matches the text of the compiler error / warn
- [**CS1018**](#constructor-calls-with-base-and-this): *Keyword 'this' or 'base' expected.*
- [**CS8054**](#constructor-declaration): *Enums cannot contain explicit parameterless constructors.*
- [**CS8091**](#constructor-declaration): *cannot be extern and have a constructor initializer.*
- [**CS8760**](#constructor-declaration): *'event': extern event cannot have initializer.*
- [**CS8358**](#constructor-declaration): *Cannot use attribute constructor because it has 'in' or 'ref readonly' parameters.*
- [**CS8813**](#module-initializer-declarations): *A module initializer must be an ordinary member method*
- [**CS8814**](#module-initializer-declarations): *Module initializer method 'method' must be accessible at the module level*
Expand Down Expand Up @@ -212,6 +215,7 @@ To correct these errors, ensure your static constructor declaration follows thes
- **CS8054**: *Enums cannot contain explicit parameterless constructors.*
- **CS8358**: *Cannot use attribute constructor because it has 'in' or 'ref readonly' parameters.*
- **CS8091**: *A constructor cannot be extern and have a constructor initializer.*
- **CS8760**: *'event': extern event cannot have initializer.*

You can declare constructors only in `class` and `struct` types, including `record class` and `record struct` types. For more information, see [Instance constructors](../../programming-guide/classes-and-structs/instance-constructors.md).

Expand All @@ -221,6 +225,7 @@ To fix these errors, try the following suggestions:
- Remove instance constructors from static classes, because static classes can't be instantiated and therefore can't have instance constructors (**CS0710**). If you need initialization logic, use a static constructor instead.
- Change `in` or `ref readonly` parameters to pass-by-value parameters in attribute constructors, because attribute constructors don't support `in` or `ref readonly` parameter modifiers (**CS8358**). The runtime instantiates attributes by using reflection, which doesn't support the `in` or `ref readonly` modifier.
- Remove the `: base()` or `: this()` constructor initializer from an `extern` constructor, because extern constructors can't chain to other constructors (**CS8091**). The implementation of an extern constructor is provided externally, so constructor chaining isn't possible.
- Remove the initializer from an `extern` event declaration (**CS8760**). Extern events have their add and remove accessors provided by external code, so a field initializer in the source has no effect and isn't permitted by the compiler.

The following warning can be generated for constructor declarations:

Expand Down
15 changes: 0 additions & 15 deletions docs/csharp/language-reference/compiler-messages/cs0006.md

This file was deleted.

17 changes: 0 additions & 17 deletions docs/csharp/language-reference/compiler-messages/cs0007.md

This file was deleted.

15 changes: 0 additions & 15 deletions docs/csharp/language-reference/compiler-messages/cs0016.md

This file was deleted.

42 changes: 0 additions & 42 deletions docs/csharp/language-reference/compiler-messages/cs1564.md

This file was deleted.

39 changes: 0 additions & 39 deletions docs/csharp/language-reference/compiler-messages/cs1616.md

This file was deleted.

Loading
Loading