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

ConfigurationBinder.Bind is not linker friendly #41658

Closed
benaadams opened this issue Sep 1, 2020 · 8 comments
Closed

ConfigurationBinder.Bind is not linker friendly #41658

benaadams opened this issue Sep 1, 2020 · 8 comments
Labels
area-Extensions-Configuration linkable-framework Issues associated with delivering a linker friendly framework untriaged New issue has not been triaged by the area owner

Comments

@benaadams
Copy link
Member

If Configuration.Bind is called on a type an it is the only method of setting its properties all the properties will be removed at link time and the configuration then will not set for bind

public static void Bind(this IConfiguration configuration, object instance, Action<BinderOptions> configureOptions)

Repo, link with <TrimMode>Link</TrimMode>

using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;

var config = new ConfigurationBuilder()
            .AddInMemoryCollection(new[]
            {
                KeyValuePair.Create("Value", "100")
            })
            .Build();
var poco = new Poco();
config.Bind(poco);

Console.WriteLine(poco.Value);

public class Poco
{
    public int Value { get; set; }
}

Will output 0 rather than 100

This issue currently occurs for certificates in Kestrel dotnet/aspnetcore#25482 meaning https certs cannot be set via config if ASP.NET Core is trimmed; also for IdentityServer.Configuration.KeyDefinition as they both use .Bind(value)

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Sep 1, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@campersau
Copy link
Contributor

Similar to #40551

@davidfowl
Copy link
Member

cc @eerhardt

@eerhardt
Copy link
Member

eerhardt commented Sep 1, 2020

Duplicate of #40551. Closing.

@eerhardt eerhardt closed this as completed Sep 1, 2020
@davidfowl
Copy link
Member

davidfowl commented Sep 1, 2020

Similar but not the same. The other issue there's a type parameter, this is an object parameter. This also isn't about object creation but about the fact that property setters get removed.

@eerhardt
Copy link
Member

eerhardt commented Sep 1, 2020

The other issue covers that the whole assembly isn't linker-safe.

@davidfowl
Copy link
Member

davidfowl commented Sep 1, 2020

It doesn't call out this problem in the description of the issue. Basically anything that uses config binding is busted in a very specific way (recursive properties or not).

@eerhardt
Copy link
Member

eerhardt commented Sep 1, 2020

The second paragraph of #40551 states:

The linker could decide to trim property setters and constructors which would cause the binder to not set properties correctly.

And the title of the issue is "Microsoft.Extensions.Configuration.Binder is not linker-safe".

I don't see any reason why we would need to keep 2 issues open to track the same problem.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-Configuration linkable-framework Issues associated with delivering a linker friendly framework untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

7 participants