Skip to content

[Broken Build]: Error IDE0040: Accessibility modifiers required #78295

Closed

Description

@bj8sk

Issue Description

I get Error IDE0040: Accessibility modifiers required on lot's of interfaces in my build overnight on hosted agents, why did you add a breaking changes in a minor upgrade with 9.0.2?

I suspect it's this one: #74245

Steps to Reproduce

The hosted agents yesterday on 9.0.102 works fine. the new builds today fetched dotnet 9.0.200, and fails all over the place.

Expected Behavior

I expect builds not to break on a minor upgrade.

Actual Behavior

Builds break.

Ask us questions

No response

Activity

  1. BenjaminBrienen commented on Feb 12, 2025

    @BenjaminBrienen

    why did you add a breaking changes in a minor upgrade with 9.0.2

    Fixing a bug is not a breaking change

  2. baronfel commented on Feb 12, 2025

    @baronfel
    Member

    @BenjaminBrienen we do consider fixing bugs that will break builds unexpectedly as a breaking change from the perspective of deciding when the change should roll out. Analysis bugs are especially thorny here - we ideally would like updates to new SDK feature bands to not break users, and so if we had applied our principles uniformly there's a real chance that we would have delayed this enforcement to .NET 10 TFMs.

    @bj8sk did you have your editorconfig set up to request errors for this diagnostic, or was this a change in default editorconfig configuration that caught you?

  3. bj8sk commented on Feb 12, 2025

    @bj8sk
    Author

    Have this line in .editorconfig for a while without issues until today:
    dotnet_diagnostic.IDE0040.severity = error # Accessibility modifiers required

  4. CyrusNajmabadi commented on Feb 12, 2025

    @CyrusNajmabadi
    Contributor

    Have this line in .editorconfig for a while without issues until today:

    What items are reporting issues where they are missing accessibility modifiers?

  5. CyrusNajmabadi commented on Feb 12, 2025

    @CyrusNajmabadi
    Contributor

    we ideally would like updates to new SDK feature bands to not break users, and so if we had applied our principles uniformly

    Note: These are Roslyn IDE warnings. And we have never had an 'bug fixes cannot be made' when it comes to analyzers. If SDK pulls in our analyzers and has their own bar here, then i think some system will have to happen on the SDK to not update analyzers until an appropriate release happens. :)

  6. jaredpar commented on Feb 12, 2025

    @jaredpar
    Member

    These are Roslyn IDE warnings.

    They are also compiler warnings and hence fall into the build diagnostics category.

  7. CyrusNajmabadi commented on Feb 12, 2025

    @CyrusNajmabadi
    Contributor

    As mentioned, we've never had a "bug fixes cannot be made" when it comes to analyzers. We've likely fixed thousands of issues over the years which change what analyzers report. Analyzers have always been suggestions from us, and up to users as to how they integrate those suggestions into their experiences. We've genuinely never had a constraint (since the beginning) on being able to update our analyzers in this way.

    Note: SDK may have such rules. But our agreement with SDK on consuming us was that we would continue development of our features as we have so far, as we don't want to add limitations and constraints on our mainline scenarios. If SDK has limitations/constraints, i think we'll have to figure out what to do on that end. Perhaps not taking Roslyn IDE analyzer updates, except on certain cadences.

  8. jaredpar commented on Feb 12, 2025

    @jaredpar
    Member

    Perhaps not taking Roslyn IDE analyzer updates, except on certain cadences.

    That is not realistic for many other reasons.

    We've genuinely never had a constraint (since the beginning) on being able to update our analyzers in this way.

    No one has said this constraint exists. @baronfel noted that analyzers, and compilers, can be thorny cases here. When the change is impactful though we give consideration to adding an entry in the breaking changes documentation so customers are aware.

  9. CyrusNajmabadi commented on Feb 12, 2025

    @CyrusNajmabadi
    Contributor

    we give consideration to adding an entry in the breaking changes documentation so customers are aware.

    I think we could do that. But it would def be a challenge as every analyzer bugfix seems to apply here. This is because any new suggestion that appears could break if a user has elevated that suggestion to a warning. Similarly, any suggestion that is removed could break a user if they have suppressed that suggestion, and have a warning on for unnecessary suppressions. :)

    I'm primarily saying that we've been shipping and changing analyzers constantly (both in Roslyn and Roslyn-Analyzers), and haven't ever been adding such documentation. So while i'm not opposed to discussion on this or going that route, I'm def leaning more to: If we haven't needed this yet, do we really need it now?

    Put in other words: what has changed to cause us to feel that we need to adjust our processes now? Thanks!

  10. jaredpar commented on Feb 12, 2025

    @jaredpar
    Member

    Put in other words: what has changed to cause us to feel that we need to adjust our processes now?

    This is a case where the change had a non-trivial impact on a real world scenario. At that point it is more likely that it could impact other customers and raises to the level of put in a breaking change notification to increase visibility. This is not a change in process, this is how we've operated for some time.

  11. CyrusNajmabadi commented on Feb 12, 2025

    @CyrusNajmabadi
    Contributor

    This is a case where the change had a non-trivial impact on a real world scenario.

    Could you clarify what distinguishes that from other reports we have in the past where people have reported we're now reporting more and our position has been that that's how IDE analyzers work?

    Basically, I'm not seeing what's different here. Or what set of rules i would apply that would cause us to not say anything about all the prior occurrences, but would here?

    this is how we've operated for some time.

    I think i'm pushing back on that. I could be wrong. But i don't recall any other times when we've done this for IDE analyzers, despite routinely updating/augmenting them in ways that impact codebases.

    That we can update our analyzers and cause new suggestions to raised is a virtue that we have taken advantage of numerous times. For example, analyzers detecting broader sets of patterns to be able to help customers refine.

    and raises to the level of put in a breaking change notification to increase visibility

    Note: i have no problem with this. My general thought though is simply that the best thing in that case is that every change to analyzers taht impacts their results goes into the breaking changes doc.

  12. jaredpar commented on Feb 12, 2025

    @jaredpar
    Member

    Could you clarify what distinguishes that from other reports we have in the past where people have reported we're now reporting more and our position has been that that's how IDE analyzers work?

    IDE analyzers do not get any sort of special treatment here. They are a part of build that produces diagnostics. No one at that level has the license to change diagnostics as they desire. Instead they need to fall into the existing structure with which we introduce and change existing diagnostics.

    In terms of what distinguishes this from other cases: whether to add a breaking change notice is hand wavy. At the moment we're pretty sensitive to breaks and hence erroring on the side of do over do not.

    But i don't recall any other times when we've done this for IDE analyzers, despite routinely updating/augmenting them in ways that impact codebases.

    The IDE has made at least four changes in the last 10 months to back out new diagnostics that adversely impacted customer builds. This is not the level of back out but potentially in the level of "add a notice". True the IDE hasn't yet had to add a notice for impactful changes, mostly because they've backed out changes instead, but that doesn't mean the IDE is immune from them.

    That we can update our analyzers and cause new suggestions to raised is a virtue that we have taken advantage of numerous times. For example, analyzers detecting broader sets of patterns to be able to help customers refine.

    Every time you do that you're taking a calculated risk.

  13. tj-concentrix commented on Feb 13, 2025

    @tj-concentrix

    This is an issue for us too because we have this set to a warning and our pipeline builds set --warnaserror. So after upgrading to 9.0.2, any interface member which has a public modifier is now a warning & our builds are failing.

    We're using the default value of for_non_interface_members, which is documented as "Prefer accessibility modifiers except for public interface members."

    In the past, this has meant "this is not enforced one way or the other for interfaces" which is what we want. But now, the meaning has changed so that they're explicitly not allowed.

    So my questions are:

    1. Was this an unintended consequence of the linked bugfix, or was this always what is was "supposed" to mean?
    2. Is it possible via .editorconfig to configure this rule so that it's a warning for non-interfaces but none for interfaces?
  14. CyrusNajmabadi commented on Feb 13, 2025

    @CyrusNajmabadi
    Contributor

    Was this an unintended consequence

    No. This was the intended way for this to work.

    or was this always what is was "supposed" to mean?

    Yup. It was always intended to work this way.

    Is it possible via .editorconfig to configure this rule so that it's a warning for non-interfaces but none for interfaces?

    No.

    But if you have for_non_interface_members, then why do you have accessibility modifiers on interfaces? :)

    If you do want accessibility modifiers on interfaces, tehn you can just set this option to always instead. for_non_interface_members exists precisely for the common .Net coding pattern where everything must have accessibility mods except interface members, since those didn't previously allow modifiers, and have been understood to be public since the start of C# :)

  15. tj-concentrix commented on Feb 13, 2025

    @tj-concentrix

    But if you have for_non_interface_members, then why do you have accessibility modifiers on interfaces? :)

    We want to leave it up to the developers on whether to add them on interface members. Especially when used with default interface implementations, it can make it more clear.

    But for all other types, we want to require them, even if they're the default.

    If you do want accessibility modifiers on interfaces, tehn you can just set this option to always instead.

    That would break all of our existing code that was written before C# 8. Even if we decided to enforce them for consistency everywhere in new code, it's not feasible for us to make this change globally to all the old code.

  16. 26 remaining items

  17. ghost added
    untriagedIssues and PRs which have not yet been triaged by a lead
    on Apr 24, 2025
  18. transferred this issue fromdotnet/msbuildon Apr 24, 2025
  19. WimLeflere commented on Sep 24, 2025

    @WimLeflere

    Has this issue been fixed? In which version?
    With dotnet v9.0.305 is still seems to occur.

  20. CyrusNajmabadi commented on Sep 24, 2025

    @CyrusNajmabadi
    Contributor

    Has this issue been fixed? In which version?
    With dotnet v9.0.305 is still seems to occur.

    @WimLeflere what issue are you referring to? What incorrect behavior are you seeing?

  21. WimLeflere commented on Sep 24, 2025

    @WimLeflere

    I'm still getting error IDE0040 for fields in a public interface.
    Image

    public interface IAudioConfig
    {
       bool IsEnabled { get; set; }
    }
    
  22. CyrusNajmabadi commented on Sep 24, 2025

    @CyrusNajmabadi
    Contributor

    @WimLeflere what does your editorconfig look like?

  23. WimLeflere commented on Sep 24, 2025

    @WimLeflere
    [*.{cs,vb}]
    dotnet_style_require_accessibility_modifiers = always:error
    
  24. CyrusNajmabadi commented on Sep 24, 2025

    @CyrusNajmabadi
    Contributor

    You have stated that you always require accessibility modifiers. And your bool IsEnabled { get; set; } member lacks a modifier. So you are getting an error (as per your settings).

    If you want an exception for interface members, you can say = for_non_interface_members:error.

  25. WimLeflere commented on Sep 24, 2025

    @WimLeflere

    Thanks, that resolves the issue.

  26. locked as resolved and limited conversation to collaborators on Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions