Closed RachelDavids closed 5 months ago
I do not reproduce the error. Here's the full csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<MeziantouPolyfill_IncludedPolyfills>T:System.Index|T:System.Range</MeziantouPolyfill_IncludedPolyfills>
<MeziantouPolyfill_ExcludedPolyfills>M:System</MeziantouPolyfill_ExcludedPolyfills>
</PropertyGroup>
<ItemGroup Label="CodeGenerators">
<PackageReference Include="Meziantou.Polyfill" Version="1.0.38">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
I do reproduce the issue. I was just targeting a recent TFM instead of an older one.
This is the expected behavior. When you set the MeziantouPolyfill_IncludedPolyfills
property, you must set all the required types. Otherwise, they won't be generated. That's why you must include DoesNotReturnAttribute
and NotNullWhenAttribute
.
Version of the Meziantou.Polyfill NuGet package
1.0.38
Description
Generated code for System.Index requires both System.Diagnostics.CodeAnalysis.NotNullWhenAttribute and System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute
Reproduction Steps
Add the following to the project file.
Build generates the following errors ..\obj\Debug\netstandard2.0\gen\Meziantou.Polyfill\Meziantou.Polyfill.PolyfillGenerator\T_System.Index.g.cs(119,78): error CS0122: 'NotNullWhenAttribute' is inaccessible due to its protection level [S:\Projects\Rachel\Tools\BuildAsSdk\MSBuild\Tasks\MSBuild.Tasks.csproj] ..\obj\Debug\netstandard2.0\gen\Meziantou.Polyfill\Meziantou.Polyfill.PolyfillGenerator\T_System.Index.g.cs(147,54): error CS0122: 'DoesNotReturnAttribute' is inaccessible due to its protection level [S:\Projects\Rachel\Tools\BuildAsSdk\MSBuild\Tasks\MSBuild.Tasks.csproj] ..\obj\Debug\netstandard2.0\gen\Meziantou.Polyfill\Meziantou.Polyfill.PolyfillGenerator\T_System.Range.g.cs(111,54): error CS0122: 'DoesNotReturnAttribute' is inaccessible due to its protection level [S:\Projects\Rachel\Tools\BuildAsSdk\MSBuild\Tasks\MSBuild.Tasks.csproj] ..\obj\Debug\netstandard2.0\gen\Meziantou.Polyfill\Meziantou.Polyfill.PolyfillGenerator\T_System.Range.g.cs(38,78): error CS0122: 'NotNullWhenAttribute' is inaccessible due to its protection level [S:\Projects\Rachel\Tools\BuildAsSdk\MSBuild\Tasks\MSBuild.Tasks.csproj]
Other information
Workaround is possible by adding the two additional types to the MeziantouPolyfill_IncludedPolyfills property