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

ExcludeFromCodeCoverage is inaccessible due to its protection level (version 3.3.37) #552

Open
NightOwl888 opened this issue Dec 18, 2020 · 5 comments

Comments

@NightOwl888
Copy link

I tried upgrading from 3.0.28 to 3.3.37, but started getting this error.

error CS0122: 'ExcludeFromCodeCoverageAttribute' is inaccessible due to its protection level

The problem appears to be compilation constants on the generated file for this attribute:

#if NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
#endif

.NET Core 1.x does not support ExcludeFromCodeCoverage attribute, so the constants should be changed to:

#if NETFRAMEWORK || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0 || NETCOREAPP3_1 || NETSTANDARD2_0 || NETSTANDARD2_1
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
#endif

Note that .NET 5.x is also missing from the list.

@AArnott
Copy link
Collaborator

AArnott commented Dec 19, 2020

The .NET Core 1.x failing bit is a duplicate of #452. .NET Core 1.x is out of Microsoft support so it's not interesting to support out here either.
We should do the right thing for .NET 5 though.

@NightOwl888
Copy link
Author

NightOwl888 commented Dec 19, 2020

Out of support, yes. But still the easiest way to test .NET Standard 1.x support.

Since there are not likely to be any more frameworks that do not support ExcludeFromCodeCoverageAttribute beyond .NET Core 1.x and .NET Standard 1.x, it would probably be better just to exclude the attribute in those cases and include it in all other cases.

#if NETSTANDARD1_0 || NETSTANDARD1_1 || NETSTANDARD1_2 || NETSTANDARD1_3 || NETSTANDARD1_4 || NETSTANDARD1_5 || NETSTANDARD1_6 || NETCOREAPP1_0 || NETCOREAPP1_1
#else
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
#endif

.NET 6 is coming out next year and the plan is to release a new major version every year after that, so this would help to future-proof.

@AArnott
Copy link
Collaborator

AArnott commented Dec 20, 2020

Well, if you want to send a PR to fix both cases, that's fine.
But using the positive test rather than the negative is fine too (even preferable) because starting with NET5_0, they're going to keep defining that symbol even post-5.0.

@KalleOlaviNiemitalo
Copy link

starting with NET5_0, they're going to keep defining that symbol even post-5.0.

It looks like that plan was changed in dotnet/sdk#13377 and dotnet/sdk#14798; they're going to define NET5_0_OR_GREATER instead.

@AArnott
Copy link
Collaborator

AArnott commented Apr 17, 2021

That's great to hear, @KalleOlaviNiemitalo. Thanks for sharing.

orgiele added a commit to orgiele/Nerdbank.GitVersioning that referenced this issue Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants