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

Configuration-binding source generator: Binding logic was not generated for a binder call #89732

Closed
eduherminio opened this issue Jul 31, 2023 · 4 comments · Fixed by #89537
Closed

Comments

@eduherminio
Copy link
Member

Description

I'm trying to use the new configuration-binding source generator in my console application, but it's not working for my use case and I'm not sure why.
I'm getting: warning SYSLIB1104: Binding logic was not generated for a binder call. Unsupported input patterns include generic calls and passing boxed objects.


Context: this same code, if compiled with /p:PublishTrimmed=true stops working as expected and reading the values from the configuration files/env variables.
That's why I'm looking to move to the source generator asap.
Any workaround until it works properly is also welcome, of course 😊

Reproduction Steps

Given:

public static class Configuration
{
    public static GeneralSettings GeneralSettings { get; set; } = new GeneralSettings();
}

public sealed class GeneralSettings
{
    public bool DisableLogging { get; set; } = false;
}

This bind call isn't behaving as expected:

var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";
var config = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
    .AddJsonFile($"appsettings.{environmentName}.json", optional: true, reloadOnChange: true)
    .AddEnvironmentVariables()
    .Build();

config.GetRequiredSection(nameof(GeneralSettings)).Bind(Configuration.GeneralSettings); // <-----------------

Expected behavior

Source generator is used

Actual behavior

Source generator isn't used and warning is triggered, therefore can't trim the app properly and load the configuration from file/env variable.

Regression?

No response

Known Workarounds

No response

Configuration

.NET SDK:
 Version:   8.0.100-preview.6.23330.14
 Commit:    ba97796b8f

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win10-x64

Other information

Same error as in #89273, but no generics involved here.

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

ghost commented Jul 31, 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'm trying to use the new configuration-binding source generator in my console application, but it's not working for my use case and I'm not sure why.
I'm getting: warning SYSLIB1104: Binding logic was not generated for a binder call. Unsupported input patterns include generic calls and passing boxed objects.


Context: this same code, if compiled with /p:PublishTrimmed=true stops working as expected and reading the values from the configuration files/env variables.
That's why I'm looking to move to the source generator asap.
Any workaround until it works properly is also welcome, of course 😊

Reproduction Steps

Given:

public static class Configuration
{
    public static GeneralSettings GeneralSettings { get; set; } = new GeneralSettings();
}

public sealed class GeneralSettings
{
    public bool DisableLogging { get; set; } = false;
}

This bind call isn't behaving as expected:

var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";
var config = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
    .AddJsonFile($"appsettings.{environmentName}.json", optional: true, reloadOnChange: true)
    .AddEnvironmentVariables()
    .Build();

config.GetRequiredSection(nameof(GeneralSettings)).Bind(Configuration.GeneralSettings); // <-----------------

Expected behavior

Source generator is used

Actual behavior

Source generator isn't used and warning is triggered, therefore can't trim the app properly and load the configuration from file/env variable.

Regression?

No response

Known Workarounds

No response

Configuration

.NET SDK:
 Version:   8.0.100-preview.6.23330.14
 Commit:    ba97796b8f

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win10-x64

Other information

Same error as in #89273, but no generics involved here.

Author: eduherminio
Assignees: -
Labels:

untriaged, area-Extensions-Configuration

Milestone: -

@tarekgh tarekgh added this to the 8.0.0 milestone Jul 31, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jul 31, 2023
@layomia
Copy link
Contributor

layomia commented Jul 31, 2023

Thanks. Related to #89537 & #89273. Will fix in that PR if I can repro with latest bits.

@eduherminio
Copy link
Member Author

Thanks to you for the quick answer, a real project to reproduce it is lynx-chess/Lynx, net-8 branch.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 31, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Aug 1, 2023
@eduherminio
Copy link
Member Author

@layomia Did it make the cut for preview-7?

eduherminio added a commit to lynx-chess/Lynx that referenced this issue Aug 19, 2023
- Replace `GeneralSettings.DisableLogging` with `GeneralSettings.EnableLogging` and set it to `false` in `Configuration.cs`
- Map it manually on startup to avoid dotnet/runtime#89732
This should avoid the issue of the binary being dependent on `appsettings.json`, unless logging is required
eduherminio added a commit to lynx-chess/Lynx that referenced this issue Aug 19, 2023
- Replace `GeneralSettings.DisableLogging` with `GeneralSettings.EnableLogging` and set it to `false` in `Configuration.cs`
- Map it manually on startup to avoid dotnet/runtime#89732

This should avoid the issue of the binary crashing without `appsettings.json`.
**This doesn't mean it should be used without it**, it will swallow all errors and arnings, but yeah, you can. 

- Add test to ensure that `appsettings.json` are `Configuration.cs` are sync'ed
- Adjust `appsettings` values to Config ones
@ghost ghost locked as resolved and limited conversation to collaborators Sep 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants