Bearbeiten

Freigeben über


Errors and warnings related to partial type and partial member declarations

There are numerous errors related to partial type and partial member declarations:

  • CS0260: Missing partial modifier on declaration of type; another partial declaration of this type exists
  • CS0261: Partial declarations of type must be all classes, all structs, or all interfaces
  • CS0262: Partial declarations of type have conflicting accessibility modifiers
  • CS0263: Partial declarations of type must not specify different base classes
  • CS0264: Partial declarations of type must have the same type parameter names in the same order
  • CS0265: Partial declarations of type have inconsistent constraints for type parameter 'type parameter'
  • CS0267: The partial modifier can only appear immediately before 'class', 'record', 'struct', 'interface', or a method return type.
  • CS0282: There is no defined ordering between fields in multiple declarations of partial class or struct 'type'. To specify an ordering, all instance fields must be in the same declaration.
  • CS0501: 'member function' must declare a body because it is not marked abstract, extern, or partial
  • CS0750: A partial member cannot have the 'abstract' modifier.
  • CS0751: A partial member must be declared in a partial class or partial struct
  • CS0754: A partial member may not explicitly implement an interface method.
  • CS0755: Both partial method declarations must be extension methods or neither may be an extension method.
  • CS0756: A partial method may not have multiple defining declarations.
  • CS0757: A partial method may not have multiple implementing declarations.
  • CS0759: No defining declaration found for implementing declaration of partial method.
  • CS0761: Partial method declarations of method<T> have inconsistent type parameter constraints.
  • CS0762: Cannot create delegate from method because it is a partial method without an implementing declaration
  • CS0763: Both partial method declarations must be static or neither may be static.
  • CS0764: Both partial method declarations must be unsafe or neither may be unsafe
  • CS1067: Partial declarations must have the same type parameter names and variance modifiers in the same order.
  • CS8142: Both partial member declarations must use the same tuple element names.
  • CS8663: Both partial member declarations must be readonly or neither may be readonly
  • CS8796: Partial method must have accessibility modifiers because it has a non-void return type.
  • CS8795: Partial member must have an implementation part because it has accessibility modifiers.
  • CS8797: Partial method must have accessibility modifiers because it has 'out' parameters.
  • CS8798: Partial method must have accessibility modifiers because it has a 'virtual', 'override', 'sealed', 'new', or 'extern' modifier.
  • CS8799: Both partial member declarations must have identical accessibility modifiers.
  • CS8800: Both partial member declarations must have identical combinations of virtual, override, sealed, and new modifiers.
  • CS8817: Both partial method declarations must have the same return type.
  • CS8818: Partial member declarations must have matching ref return values.
  • CS8863: Only a single partial type declaration may have a parameter list
  • CS8988: The scoped modifier of parameter doesn't match partial definition.
  • CS9248: Partial property must have an implementation part.
  • CS9249: Partial property must have a definition part.
  • CS9250: A partial property may not have multiple defining declarations, and cannot be an auto-property.
  • CS9251: A partial property may not have multiple implementing declarations
  • CS9252: Property accessor must be implemented because it is declared on the definition part
  • CS9253: Property accessor does not implement any accessor declared on the definition part
  • CS9254: Property accessor must match the definition part
  • CS9255: Both partial property declarations must have the same type.
  • CS9256: Partial property declarations have signature differences.
  • CS9257: Both partial property declarations must be required or neither may be required

The following sections explain the cause and fixes for these errors and warnings.

Partial types

  • CS0260: Missing partial modifier on declaration of type; another partial declaration of this type exists
  • CS0261: Partial declarations of type must be all classes, all structs, or all interfaces
  • CS0262: Partial declarations of type have conflicting accessibility modifiers
  • CS0263: Partial declarations of type must not specify different base classes
  • CS0264: Partial declarations of type must have the same type parameter names in the same order
  • CS0265: Partial declarations of type have inconsistent constraints for type parameter 'type parameter'
  • CS0267: The partial modifier can only appear immediately before 'class', 'record', 'struct', 'interface', or a method return type.
  • CS8863: Only a single partial type declaration may have a parameter list

Your partial type declaration can cause the compiler to emit the following warning:

  • CS0282: There is no defined ordering between fields in multiple declarations of partial class or struct 'type'. To specify an ordering, all instance fields must be in the same declaration.

For any partial type, the partial keyword must immediately precede class, record, struct, or interface. The compiler emits an error if it appears in any other order. In addition:

  • All declarations of a partial type must match in terms of the type (class, struct, record class, record struct, readonly struct, or readonly record struct).
  • All declarations must include the partial modifier.
  • The declarations for a generic partial type must include the same type parameters in the same order.

Some parts of the declaration aren't required to be repeated on all declarations for a type. However, if these elements are repeated on multiple partial declarations, they must match:

  • Any access modifiers, such as public.
  • Any base class or implemented interfaces.
  • Any constraints on type parameters.

A primary constructor can be declared on at most one declaration for a partial type.

The compiler warns you if you have multiple fields declared in multiple files for a partial struct type. If the layout order is important, you must declare all fields in the same file. If order doesn't matter, you can use the System.Runtime.InteropServices.StructLayoutAttribute with the LayoutKind.Auto value.

Partial members

  • CS0750: A partial member cannot have the 'abstract' modifier.
  • CS0751: A partial member must be declared in a partial class or partial struct
  • CS0754: A partial member may not explicitly implement an interface method.
  • CS0763: Both partial method declarations must be static or neither may be static.
  • CS0764: Both partial method declarations must be unsafe or neither may be unsafe
  • CS8142: Both partial member declarations must use the same tuple element names.
  • CS8663: Both partial member declarations must be readonly or neither may be readonly
  • CS8799: Both partial member declarations must have identical accessibility modifiers.
  • CS8800: Both partial member declarations must have identical combinations of virtual, override, sealed, and new modifiers.
  • CS8818: Partial member declarations must have matching ref return values.
  • CS8988: The scoped modifier of parameter doesn't match partial definition.

Partial members have two declarations. The declaration without an implementation is the declaring declaration. The declaration with the implementation is the implementing declaration. Partial members are allowed only in a partial type. Partial members can't be abstract. Partial members can't explicitly implement an interface. Both declarations of a partial member must have identical signatures. For example, either both or neither declarations can include the static or unsafe modifiers.

Partial methods

  • CS0501: 'member function' must declare a body because it is not marked abstract, extern, or partial
  • CS0755: Both partial method declarations must be extension methods or neither may be an extension method.
  • CS0756: A partial method may not have multiple defining declarations.
  • CS0757: A partial method may not have multiple implementing declarations.
  • CS0759: No defining declaration found for implementing declaration of partial method.
  • CS0761: Partial method declarations of method<T> have inconsistent type parameter constraints.
  • CS0762: Cannot create delegate from method because it is a partial method without an implementing declaration
  • CS1067: Partial declarations must have the same type parameter names and variance modifiers in the same order.
  • CS8796: Partial method must have accessibility modifiers because it has a non-void return type.
  • CS8795: Partial member must have an implementation part because it has accessibility modifiers.
  • CS8797: Partial method must have accessibility modifiers because it has 'out' parameters.
  • CS8798: Partial method must have accessibility modifiers because it has a 'virtual', 'override', 'sealed', 'new', or 'extern' modifier.
  • CS8817: Both partial method declarations must have the same return type.

Certain partial method declarations don't require an implementing declaration. That is, if the member returns void, doesn't declare any access modifiers (including the default private modifier), and doesn't include any of the virtual, override, sealed, or new modifiers. Otherwise, any partial method must include both the declaring and implementing declarations.

When a partial method includes an implementing declaration, both declarations must be identical. Exactly one implementing declaration can be defined.

Partial properties

The following errors indicate mistakes in your partial property or indexer declarations:

  • CS9248: Partial property must have an implementation part.
  • CS9249: Partial property must have a definition part.
  • CS9250: A partial property may not have multiple defining declarations, and cannot be an auto-property.
  • CS9251: A partial property may not have multiple implementing declarations
  • CS9252: Property accessor must be implemented because it is declared on the definition part
  • CS9253: Property accessor does not implement any accessor declared on the definition part
  • CS9254: Property accessor must match the definition part
  • CS9255: Both partial property declarations must have the same type.
  • CS9257: Both partial property declarations must be required or neither may be required

The following warning indicates a signature difference in the declaring and implementing declarations in a partial property:

  • CS9256: Partial property declarations have signature differences.

A partial property or indexer must have both a declaring declaration and an implementing declaration. The signatures for both declarations must match. Because the declaring declaration uses the same syntax as an auto-implemented property, the implementing declaration can't be an auto-implemented property. The accessors must have bodies.