-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescriptionI'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. Context: this same code, if compiled with Reproduction StepsGiven: 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 behaviorSource generator is used Actual behaviorSource 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 WorkaroundsNo response Configuration
Other informationSame error as in #89273, but no generics involved here.
|
Thanks to you for the quick answer, a real project to reproduce it is lynx-chess/Lynx, |
@layomia Did it make the cut for |
- 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
- 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
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:
This bind call isn't behaving as expected:
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
Other information
Same error as in #89273, but no generics involved here.
The text was updated successfully, but these errors were encountered: