Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE0040 error on interface after upgrading to .NET 9.0.200 #46778

Closed
tomflenner opened this issue Feb 12, 2025 · 3 comments
Closed

IDE0040 error on interface after upgrading to .NET 9.0.200 #46778

tomflenner opened this issue Feb 12, 2025 · 3 comments
Assignees
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@tomflenner
Copy link

tomflenner commented Feb 12, 2025

Describe the bug

Hi, we are using Azure DevOps pipeline to run our test and after the .NET 9.0.200 upgrade we have some IDE0040 error showing up and lead to failure (as we have warning as error I think).

The following interface have error on the ValidationError property :

public interface IValidationResult
{
    public static readonly Error ValidationError = new("ValidationError", "A validation problem occurred.");

    /// <summary>
    ///     Gets the errors.
    /// </summary>
    Error[] Errors { get; }
}

To Reproduce

I setup a class library project with the following files :

IFoo.cs

namespace ClassLibrary1;

public interface IFoo
{
    public static readonly string FooString = "foo";
}

Foo.cs

namespace ClassLibrary1;

public class Foo : IFoo
{
    private string FooValue { get; set; }= IFoo.FooString;
}

It seems like defining the access modifier inside the interface throw error

Exceptions (if any)

Further technical details

  • Using JetBrains Rider 2024.3.5
  • Add a Directory.Build.props file :
<Project>
    <PropertyGroup>
        <TargetFramework>net9.0</TargetFramework>
        <AnalysisLevel>9.0</AnalysisLevel>
        <AnalysisMode>All</AnalysisMode>
        <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
        <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
        <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <GenerateDocumentationFile>true</GenerateDocumentationFile>
        <DocumentationFile>bin\$(MSBuildProjectName).xml</DocumentationFile>
        <!-- warning CS1591: Missing XML comment for publicly visible type or member -->
        <NoWarn>1591,1574</NoWarn>
    </PropertyGroup>
</Project>
  • Add a .editorconfigfile :
root = true

# Common props file & C# files
[{*.props,*.cs}]

dotnet_style_require_accessibility_modifiers = for_non_interface_members:error

The bug does not seems to be related to Rider because of the Azure DevOps pipeline failure.

If you have more question, don't hesitate !

Thanks in advance 🙏🏻

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Feb 12, 2025
@KalleOlaviNiemitalo
Copy link
Contributor

May be the same as dotnet/msbuild#11426

@baronfel
Copy link
Member

Yeah, it's all the same issue. Thanks for the link @KalleOlaviNiemitalo. @tomflenner I'm assuming you requested that this diagnostic be reported as an error in your .editorconfig?

@andrew-longmore-tessella

This catches me out about once a year! Part of the confusion is that the .Net version in ADO goes up before the latest version of Visual Studio comes out with the same .Net version, so there's a bit of head scratching whilst you figure out why you have no warnings in VS but there are some in the pipeline. When this happens, I change my UseDotNet@2 step in my pipeline to a specific version of .NET, matching what I have locally from Visual Studio (which I can find out from dotnet --list-sdks). Then once VS catches up I change it back to 9.0.x etc. Hope that helps others.

@marcpopMSFT marcpopMSFT self-assigned this Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

5 participants