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

CS9270 'InterceptsLocationAttribute(string, int, int)' is not supported when using Microsoft.Extensions.Configuration.Binder 8.0.x #76641

Open
eerhardt opened this issue Jan 2, 2025 · 16 comments · May be fixed by #76642

Comments

@eerhardt
Copy link
Member

eerhardt commented Jan 2, 2025

Version Used: C# Tools 4.13.0-3.24620.4+98ea496177bc8e607dbf454abd6b5a5e4678aed2

Steps to Reproduce:

  1. 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		

cc @ericstj @tarekgh @RikkiGibson

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Jan 2, 2025
@eerhardt
Copy link
Member Author

eerhardt commented Jan 2, 2025

eerhardt referenced this issue in eerhardt/aspire Jan 2, 2025
The 8.0.x version of Microsoft.Extensions.Configuration.Binder is using an old/deprecated approach to the interception feature in Roslyn. Using the latest version of Roslyn produces warnings (which turn into errors in the repo).

Workaround https://github.com/dotnet/roslyn/issues/76600
@tarekgh
Copy link
Member

tarekgh commented Jan 2, 2025

CC @steveharter

@eerhardt
Copy link
Member Author

eerhardt commented Jan 2, 2025

Note - this issue could be moved to dotnet/runtime, if the plan is to update and ship a Microsoft.Extensions.Configuration.Binder v8.0.x version that doesn't cause the warning. I wasn't sure which repo to report the issue in, so I picked the repo that made the latest change to cause the problem.

eerhardt referenced this issue in dotnet/aspire Jan 2, 2025
The 8.0.x version of Microsoft.Extensions.Configuration.Binder is using an old/deprecated approach to the interception feature in Roslyn. Using the latest version of Roslyn produces warnings (which turn into errors in the repo).

Workaround https://github.com/dotnet/roslyn/issues/76600
@eerhardt
Copy link
Member Author

eerhardt commented Jan 3, 2025

Note the same warning is emitted for 8.0 web api projects.

  1. Create new project -> ASP.NET Core Web Api (native AOT)
  2. Select net8.0 Long-Term Support
  3. Create
  4. Build
Severity	Code	Description	Project	File	Line	Suppression State	Details
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)	WebApplication3	D:\source\WebApplication3\WebApplication3\obj\Debug\net8.0\Microsoft.AspNetCore.Http.RequestDelegateGenerator\Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator\GeneratedRouteBuilderExtensions.g.cs	61		
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)	WebApplication3	D:\source\WebApplication3\WebApplication3\obj\Debug\net8.0\Microsoft.AspNetCore.Http.RequestDelegateGenerator\Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator\GeneratedRouteBuilderExtensions.g.cs	143		

Opened: dotnet/aspnetcore#59735.

cc @captainsafia @DamianEdwards @mikekistler

@tarekgh
Copy link
Member

tarekgh commented Jan 3, 2025

We need to figure out the right fix and then we should service 8.0 if the fix comes from the runtime.

CC @RikkiGibson

@CyrusNajmabadi
Copy link
Member

This doesn't seem like a roslyn issue. the InterceptsLocationAttribute(string, int, int) was part of the experimental feature, which has since been removed in favor of the new checksum-based attribute based on the file contents.

@tarekgh
Copy link
Member

tarekgh commented Jan 3, 2025

@CyrusNajmabadi Is there any published documentation for users who were using this feature, along with guidelines for transitioning to the checksum-based attribute? I know we (.NET Libraries) implemented this in version 9.0, but I’m checking if it's documented somewhere. I've noticed some user blogs still referencing the deprecated version.

@tarekgh
Copy link
Member

tarekgh commented Jan 3, 2025

Anyone has permission transferring issues to runtime repo can help moving it there.

@CyrusNajmabadi
Copy link
Member

You can use CSharpSemanticModel.GetInterceptableLocation(invocationNode) to get an object that has the information needed to properly intercept an invocation. When generating code, you can then use iLoc.GetInterceptsLocationAttributeSyntax() to convert that to a string to emit into the generated code.

@CyrusNajmabadi CyrusNajmabadi transferred this issue from dotnet/roslyn Jan 3, 2025
@CyrusNajmabadi
Copy link
Member

Anyone has permission transferring issues to runtime repo can help moving it there.

Done :)

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

@tarekgh tarekgh removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jan 3, 2025
@tarekgh tarekgh self-assigned this Jan 3, 2025
@eerhardt
Copy link
Member Author

eerhardt commented Jan 3, 2025

This doesn't seem like a roslyn issue.

Should we hold off on enabling this compiler warning until all supported usages (ConfigurationBinder and ASP.NET Minimal APIs v8) have moved off of it?

@tarekgh
Copy link
Member

tarekgh commented Jan 3, 2025

You can use CSharpSemanticModel.GetInterceptableLocation(invocationNode) to get an object that has the information needed to properly intercept an invocation. When generating code, you can then use iLoc.GetInterceptsLocationAttributeSyntax() to convert that to a string to emit into the generated code.

That is what we do in 9.0:
https://github.com/dotnet/runtime/blob/27fd292671ba8208b881e9f1fd79eb0d8b94f471/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/ConfigurationBindingGenerator.cs#L86
https://github.com/dotnet/runtime/blob/27fd292671ba8208b881e9f1fd79eb0d8b94f471/src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Specs/InterceptorInfo.cs#L202

@jaredpar
Copy link
Member

jaredpar commented Jan 6, 2025

@RikkiGibson for doc and expected migration plan discussion

@RikkiGibson
Copy link
Contributor

RikkiGibson commented Jan 6, 2025

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 supported is only reported when targeting .NET 9 or later.

@tarekgh
Copy link
Member

tarekgh commented Jan 6, 2025

@RikkiGibson Should this issue be moved back to the Roslyn repository then?

@RikkiGibson RikkiGibson assigned RikkiGibson and unassigned tarekgh Jan 6, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 6, 2025
@RikkiGibson RikkiGibson transferred this issue from dotnet/runtime Jan 6, 2025
@RikkiGibson RikkiGibson added the Bug label Jan 6, 2025
@RikkiGibson RikkiGibson added Feature - Interceptors and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 6, 2025
@RikkiGibson RikkiGibson added this to the 17.13 milestone Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants