roslyn: CS9270 'InterceptsLocationAttribute(string, int, int)' is not supported when using Microsoft.Extensions.Configuration.Binder 8.0.x
Version Used: C# Tools 4.13.0-3.24620.4+98ea496177bc8e607dbf454abd6b5a5e4678aed2
Steps to Reproduce:
- Build https://github.com/dotnet/aspire/tree/main/src/Components/Aspire.Azure.AI.OpenAI using the latest Roslyn build
- or -
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
</ItemGroup>
</Project>
using Microsoft.Extensions.Configuration;
public class Class1
{
public static void Bind(IConfiguration config)
{
var option = new Options();
config.Bind(option);
}
}
public class Options
{
public string? Name { get; set; }
}
Diagnostic Id:
CS9270 ‘InterceptsLocationAttribute(string, int, int)’ is not supported.
Expected Behavior:
The current Long-Term Supported version of Microsoft.Extensions.Configuration.Binder should be able to be used without warnings/errors.
Actual Behavior:
You get a warning (turned into an error in repos with warning-as-error):
Warning (active) CS9270 'InterceptsLocationAttribute(string, int, int)' is not supported. Move to 'InterceptableLocation'-based generation of these attributes instead. (https://github.com/dotnet/roslyn/issues/72133) ConsoleApp3 D:\source\ConsoleApp3\ConsoleApp3\obj\Debug\net9.0\Microsoft.Extensions.Configuration.Binder.SourceGeneration\Microsoft.Extensions.Configuration.Binder.SourceGeneration.ConfigurationBindingGenerator\BindingExtensions.g.cs 38
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (16 by maintainers)
Commits related to this issue
- Work around warning from InterceptsLocationAttribute The 8.0.x version of Microsoft.Extensions.Configuration.Binder is using an old/deprecated approach to the interception feature in Roslyn. Using th... — committed to eerhardt/aspire by eerhardt 2 years ago
- Work around warning from InterceptsLocationAttribute (#7013) The 8.0.x version of Microsoft.Extensions.Configuration.Binder is using an old/deprecated approach to the interception feature in Roslyn. ... — committed to dotnet/aspire by eerhardt 2 years ago
- Remove Roslyn workaround https://github.com/dotnet/roslyn/issues/76641 is now fixed. This no longer is necessary. — committed to eerhardt/aspire by eerhardt 2 years ago
- Remove Roslyn workaround (#8509) https://github.com/dotnet/roslyn/issues/76641 is now fixed. This no longer is necessary. — committed to dotnet/aspire by eerhardt 2 years ago
It was not our goal to make generator authors service the .NET 8 versions of their generators to start using InterceptableLocation. The goal was just to get people moved to the new way for .NET 9 and up. Our plan is to leave in support for the “old way” in the SDK, for as long as .NET 8 is supported. At the time .NET 8 goes out of support, we will fully remove the support for the “old way” from the newest SDK.
I think the resolution here should be to adjust the compiler so that warning
InterceptsLocationAttribute(string, int, int) is not supportedis only reported when targeting .NET 9 or later.@RikkiGibson Should this issue be moved back to the Roslyn repository then?