Skip to content

CS8336: 'Microsoft.CodeAnalysis.EmbeddedAttribute' is reserved #143

Description

@PBeckmann-prohandel

Description (optional)

When building our source generator project we get this compiler error:
/opt/atlassian/pipelines/agent/build/SourceGenerators/obj/Debug/netstandard2.0/PolySharp.SourceGenerators/PolySharp.SourceGenerators.PolyfillsGenerator/Microsoft.CodeAnalysis.EmbeddedAttribute.g.cs(15,35): error CS8336: The type name 'Microsoft.CodeAnalysis.EmbeddedAttribute' is reserved to be used by the compiler.

Reproduction Steps

The content of the csproj.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
      <TargetFramework>netstandard2.0</TargetFramework>		
      <LangVersion>latest</LangVersion>		
      <Nullable>enable</Nullable>		
      <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
      <IsRoslynComponent>true</IsRoslynComponent>
      <IncludeBuildOutput>false</IncludeBuildOutput>		
      <EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
      <IsRoslynComponent>true</IsRoslynComponent>	
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="*">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
    <PackageReference Include="PolySharp" Version="1.16.*">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

Reverting to 1.15.* fixes the compile error.

Expected Behavior

No compile errors

Actual Behavior

Compile error CS8336 occurrs

System info

  • PolySharp 1.16.0
  • Bitbucket pipeline with image tag mcr.microsoft.com/dotnet/sdk:8.0

Activity

  1. ivarne commented on Jun 1, 2026

    @ivarne

    I'm also getting this when building from command line, but apparently not when building in rider. I'm using net8.0 on a Mac if that matters.

  2. PBeckmann-prohandel commented on Jun 1, 2026

    @PBeckmann-prohandel
    Author

    We also do not get this error when building in Visual Studio 2026 on Windows 11

  3. Sergio0694 commented on Jun 1, 2026

    @Sergio0694
    Owner

    The issue happens if you build with Roslyn < 4.14. I'll need to add a check to disable the attribute in that case.
    The workaround is to set PolySharpUseEmbeddedAttributeForGeneratedTypes=false for now if you're on old Roslyn.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions