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

Source generated configuration binder error #92343

Closed
akoken opened this issue Sep 20, 2023 · 3 comments
Closed

Source generated configuration binder error #92343

akoken opened this issue Sep 20, 2023 · 3 comments

Comments

@akoken
Copy link
Contributor

akoken commented Sep 20, 2023

Description

I followed the guide in the doc, but build fails.

Reproduction Steps

  • Create a new app: dotnet new webapiaot
  • Enable configuration binder
<PropertyGroup>
    <EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
</PropertyGroup>
  • Program.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
IConfigurationSection section = builder.Configuration.GetSection("MyOptions");

// !! Configure call - to be replaced with source-gen'd implementation
builder.Services.Configure<MyOptions>(section);

// !! Get call - to be replaced with source-gen'd implementation
MyOptions options0 = section.Get<MyOptions>();

// !! Bind call - to be replaced with source-gen'd implementation
MyOptions options1 = new MyOptions();
section.Bind(options1);

WebApplication app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();

public class MyOptions
{
    public int A { get; set; }
    public string S { get; set; }
    public byte[] Data { get; set; }
    public Dictionary<string, string> Values { get; set; }
    public List<MyClass> Values2 { get; set; }
}

public class MyClass
{
    public int SomethingElse { get; set; }
}
  • Publish application
dotnet publish -r win-x64 -c Release

Expected behavior

Program compiles without error and warnings.

Actual behavior

Build fails with the following source generation errors:

MSBuild version 17.8.0-preview-23418-03+0125fc9fb for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\8.0.100-rc.1.23463.5\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInferenc
e.targets(311,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-polic
y [C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\NativeAOT.Demo.csproj]
C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\Microsoft.Extensions.Configuration.Binder.SourceGeneration\Mi
crosoft.Extensions.Configuration.Binder.SourceGeneration.ConfigurationBindingGenerator\BindingExtensions.g.cs(80,227):
error CS1003: Syntax error, ',' expected [C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\NativeAOT.Demo.cspr
oj]
C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\Microsoft.Extensions.Configuration.Binder.SourceGeneration\Mi
crosoft.Extensions.Configuration.Binder.SourceGeneration.ConfigurationBindingGenerator\BindingExtensions.g.cs(79,35): e
rror CS0246: The type or namespace name 'IOptionsChangeTokenSource<>' could not be found (are you missing a using direc
tive or an assembly reference?) [C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\NativeAOT.Demo.csproj]
C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\Microsoft.Extensions.Configuration.Binder.SourceGeneration\Mi
crosoft.Extensions.Configuration.Binder.SourceGeneration.ConfigurationBindingGenerator\BindingExtensions.g.cs(79,76): e
rror CS0246: The type or namespace name 'ConfigurationChangeTokenSource<>' could not be found (are you missing a using
directive or an assembly reference?) [C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\NativeAOT.Demo.csproj]

Regression?

Unfortunately I'm not sure.

Known Workarounds

N/A

Configuration

Version: .NET 8 RC1
SDK: 8.0.100-rc.1.23463.5
Runtime: Microsoft.AspNetCore.App 8.0.0-rc.1.23421.29
OS: Windows 11 x64, Version 21H2 (Build 22000.2416)

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 20, 2023
@ghost
Copy link

ghost commented Sep 20, 2023

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

Issue Details

Description

I followed the guide in the doc, but build fails.

Reproduction Steps

  • Create a new app: dotnet new webapiaot
  • Add configuration binder package to *.csproj
<PropertyGroup>
    <EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
</PropertyGroup>
  • Program.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
IConfigurationSection section = builder.Configuration.GetSection("MyOptions");

// !! Configure call - to be replaced with source-gen'd implementation
builder.Services.Configure<MyOptions>(section);

// !! Get call - to be replaced with source-gen'd implementation
MyOptions options0 = section.Get<MyOptions>();

// !! Bind call - to be replaced with source-gen'd implementation
MyOptions options1 = new MyOptions();
section.Bind(options1);

WebApplication app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();

public class MyOptions
{
    public int A { get; set; }
    public string S { get; set; }
    public byte[] Data { get; set; }
    public Dictionary<string, string> Values { get; set; }
    public List<MyClass> Values2 { get; set; }
}

public class MyClass
{
    public int SomethingElse { get; set; }
}
  • Publish application
dotnet publish -r win-x64 -c Release

Expected behavior

Program compiles without error and warnings.

Actual behavior

Build fails with the following source generation errors:

MSBuild version 17.8.0-preview-23418-03+0125fc9fb for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\8.0.100-rc.1.23463.5\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInferenc
e.targets(311,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-polic
y [C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\NativeAOT.Demo.csproj]
C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\Microsoft.Extensions.Configuration.Binder.SourceGeneration\Mi
crosoft.Extensions.Configuration.Binder.SourceGeneration.ConfigurationBindingGenerator\BindingExtensions.g.cs(80,227):
error CS1003: Syntax error, ',' expected [C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\NativeAOT.Demo.cspr
oj]
C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\Microsoft.Extensions.Configuration.Binder.SourceGeneration\Mi
crosoft.Extensions.Configuration.Binder.SourceGeneration.ConfigurationBindingGenerator\BindingExtensions.g.cs(79,35): e
rror CS0246: The type or namespace name 'IOptionsChangeTokenSource<>' could not be found (are you missing a using direc
tive or an assembly reference?) [C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\NativeAOT.Demo.csproj]
C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\Microsoft.Extensions.Configuration.Binder.SourceGeneration\Mi
crosoft.Extensions.Configuration.Binder.SourceGeneration.ConfigurationBindingGenerator\BindingExtensions.g.cs(79,76): e
rror CS0246: The type or namespace name 'ConfigurationChangeTokenSource<>' could not be found (are you missing a using
directive or an assembly reference?) [C:\Users\source\repos\NativeAOT.Demo\NativeAOT.Demo\NativeAOT.Demo.csproj]

Regression?

Unfortunately I'm not sure.

Known Workarounds

Configuration

Version: .NET 8 RC1
SDK: 8.0.100-rc.1.23463.5
Runtime: Microsoft.AspNetCore.App 8.0.0-rc.1.23421.29
OS: Windows 11 x64, Version 21H2 (Build 22000.2416)

Other information

No response

Author: akoken
Assignees: -
Labels:

untriaged, area-Extensions-Configuration

Milestone: -

@jamiewinder
Copy link

Apparently due to be fixed in RC2: #92021 (comment)

@akoken
Copy link
Contributor Author

akoken commented Sep 20, 2023

Thanks @jamiewinder. Since it's the same issue, I'm closing this one.

@akoken akoken closed this as completed Sep 20, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Sep 20, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants