Skip to content

docs: Document CS8080 private accessor override limitation#55014

Open
adegeo with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-override-private-set-property
Open

docs: Document CS8080 private accessor override limitation#55014
adegeo with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-override-private-set-property

Conversation

Copilot AI commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

CS8080 was nearly undocumented—the VS error link led to a "no specifics" page, and the existing docs entry didn't cover the common case that triggers it: a base property with a private accessor.

Changes

  • property-declaration-errors.md — CS8080 bullet: Expanded the existing entry to explain that when the base class property has a private accessor (e.g., private set), an auto-implemented override is impossible because private members aren't accessible in derived classes. Adds explicit guidance to use explicit accessor bodies instead:

    class Base {
        public virtual int Member { get; private set; }
    }
    
    // ❌ CS8080 — auto-implemented can't satisfy the private set
    class Derived : Base {
        public override int Member { get; }
    }
    
    // ✅ Use explicit accessor body instead
    class Derived : Base {
        public override int Member { get => base.Member; }
    }

Internal previews

📄 File 🔗 Preview link
docs/csharp/language-reference/compiler-messages/property-declaration-errors.md docs/csharp/language-reference/compiler-messages/property-declaration-errors

Copilot AI review requested due to automatic review settings July 24, 2026 22:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because there is no eligible user to bill. To allow Copilot reviews on bot-authored pull requests, enable direct organization billing in your organization's Copilot settings.

Copilot AI linked an issue Jul 24, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix override of property with private set in derived class docs: Document CS8080 private accessor override limitation Jul 24, 2026
Copilot AI requested a review from adegeo July 24, 2026 22:06
Comment thread docs/csharp/language-reference/compiler-messages/property-declaration-errors.md Outdated
Copilot AI requested a review from adegeo July 24, 2026 22:29
@adegeo
adegeo marked this pull request as ready for review July 24, 2026 22:31
@adegeo
adegeo requested review from a team and BillWagner as code owners July 24, 2026 22:31
- Override only the accessors that exist in the base class property declaration (**CS0545**, **CS0546**). You can't override a property accessor that isn't present or accessible in the base class because there's no virtual method to override. If the base class property has only a `get` accessor, you can't add a `set` accessor through an override. Either add the missing accessor to the base class and mark it `virtual`, or use `new` to hide the base class property with a new property definition.
- Match the type of the overriding property to the type of the overridden member (**CS1715**). Read-only (`get`-only) properties support covariant return types beginning with C# 9, so the override can return a more derived type. However, properties that have a `set` or `init` accessor require an exact type match because the setter accepts values of the declared type. If you need a different type on a property with a setter, change the property type in the derived class to match the base class declaration, or remove the setter and use a covariant return type instead.
- Include all accessors from the base property when overriding with an auto-implemented property (**CS8080**). Auto-implemented properties generate both storage and accessor implementations, so they must override all accessors present in the base class. If the base property has both `get` and `set`, the auto-implemented override must also have both. To override only specific accessors, implement the property with explicit accessor bodies and an explicit backing field instead of using auto-implementation.
- Include all accessors from the base property when overriding with an auto-implemented property (**CS8080**). Auto-implemented properties generate both storage and accessor implementations, so they must override all accessors present in the base class. If the base property has both `get` and `set`, the auto-implemented override must also have both. To override only specific accessors, implement the property with explicit accessor bodies and an explicit backing field instead of using auto-implementation. If the base class property has a `private` accessor, you can't override the property with an auto-implemented property—use explicit accessor bodies instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Include all accessors from the base property when overriding with an auto-implemented property (**CS8080**). Auto-implemented properties generate both storage and accessor implementations, so they must override all accessors present in the base class. If the base property has both `get` and `set`, the auto-implemented override must also have both. To override only specific accessors, implement the property with explicit accessor bodies and an explicit backing field instead of using auto-implementation. If the base class property has a `private` accessor, you can't override the property with an auto-implemented property—use explicit accessor bodies instead.
- Include all accessors from the base property when overriding with an auto-implemented property (**CS8080**). Auto-implemented properties generate both storage and accessor implementations, so they must override all accessors present in the base class. If the base property has both `get` and `set`, the auto-implemented override must also have both. To override only specific accessors, implement the property with explicit accessor bodies and an explicit backing field instead of using auto-implementation. If the base class property has a `private` accessor, you can't override the property with an auto-implemented property. Use explicit accessor bodies instead.

Very minor, removing the em dash that had no spaces around it and breaking into two sentances.

@wadepickett wadepickett left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adegeo : LGTM. I am not up on the technical aspect of this item. Good to have someone review that is. I"m not spotting a technical issue. I did see your note on your tests.

Approved, but see very minor suggestion. Watching for any need for a re-approve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot override property with private set

4 participants