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

ActivatorUtilities.CreateInstance no selecting the longest matching constructor #2915

Closed
Tratcher opened this issue Mar 2, 2018 · 1 comment

Comments

@Tratcher
Copy link
Member

Tratcher commented Mar 2, 2018

Consider:

        public CookiePolicyMiddleware(RequestDelegate next, IOptions<CookiePolicyOptions> options)
        {
            Options = options.Value;
            _next = next;
            _logger = NullLogger.Instance;
        }
        
        public CookiePolicyMiddleware(RequestDelegate next, IOptions<CookiePolicyOptions> options, ILoggerFactory factory)
        {
            Options = options.Value;
            _next = next ?? throw new ArgumentNullException(nameof(next));
            _logger = factory.CreateLogger<CookiePolicyMiddleware>();
        }

This class is activated by UseMiddleware which calls Activator.CreateInstance.
https://github.com/aspnet/HttpAbstractions/blob/9119433ab778d7adf04c4601917809f2f4582a93/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/UseMiddlewareExtensions.cs#L92

The shorter constructor is being used by default and logging doesn't work. Either constructor works if I comment out the other.

Our breaking change policy requires adding new constructors when adding new parameters.

@pranavkm
Copy link
Contributor

pranavkm commented Mar 2, 2018

Likely a dup of #2871.

@Tratcher Tratcher closed this as completed Mar 2, 2018
@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants