Skip to content

error CS0122: 'ThisAssembly' is inaccessible due to its protection level #449

@MSThug

Description

@MSThug

Hi there I'm on a project that uses Nerdbank.GitVersioning 3.1.68. After a number of changes updating our WPF project to .NET Core 3.1 at some point we started to see the follow error.

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

To be clear this had been working. But at some point we changed our project SDK from "MSBuild.SDK.Extras" to "Microsoft.NET.Sdk.WindowsDesktop".

Of course this is because we use some of the properties from the ThisAssembly class in our code. After a number of attempts to determine the cause I finally tried defining ThisAssembly in our code as seen below.

internal static partial class ThisAssembly { internal const int IgnoreMe = 0; }

This changed all the errors all to something along the lines of the error below.

error CS0117: 'ThisAssembly' does not contain a definition for 'AssemblyVersion'

I only found a couple references to the first error online but they seemed to work around the issue by disabling GitVersioning and one eluded to the timing of when ThisAssembly is created. That would certainly explain the two different errors and the fact that I see the errors in VS after building but they very quickly disappear in the Error List panel when I navigate to the files with the errors. However, they can always be found in the build logs.

Use of GitVersioning is seems pretty straight forward and the only significant csproj file change was the SDK change. All other changes were code so I doubt they could affect this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions