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

ObjectFactory should verify against a null serviceProvider #82315

Closed
steveharter opened this issue Feb 17, 2023 · 1 comment · Fixed by #82739
Closed

ObjectFactory should verify against a null serviceProvider #82315

steveharter opened this issue Feb 17, 2023 · 1 comment · Fixed by #82739
Labels
area-Extensions-DependencyInjection breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. bug help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@steveharter
Copy link
Member

steveharter commented Feb 17, 2023

This will throw NullReferenceException, but should throw ArgumentNullException:

var f = Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateFactory(typeof(FOO), new Type[] { });
f(serviceProvider: null, arguments: null);

public class FOO {
    public FOO(int i) { }
}

See also the breaking change for CreateInstance now throwing ArgumentNullException at dotnet/docs#34158 which should be extended to mention CreateFactory. That PR added the test for a null provider for the non-factory approach but the PR did not change the factory approach or add any tests. The factory approach has more complexity since it requires an Expression to do the check and throw.

Thus, currently, the factory approach and non-factory approach have different semantics for validating against serviceProvier.

@ghost
Copy link

ghost commented Feb 17, 2023

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

Issue Details

This will throw NullReferenceException, but should throw ArgumentNullException:

var f = Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateFactory(typeof(FOO), new Type[] { });
f(serviceProvider: null, arguments: null);

public class FOO {
    public FOO(int i) { }
}

See also the breaking change for CreateInstance now throwing ArgumentNullException at dotnet/docs#34158 which should be extended to mention CreateFactory.

Author: steveharter
Assignees: -
Labels:

bug, area-Extensions-DependencyInjection

Milestone: 8.0.0

@steveharter steveharter modified the milestones: 8.0.0, Future Feb 24, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Feb 24, 2023
@steveharter steveharter added the help wanted [up-for-grabs] Good issue for external contributors label Feb 24, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Feb 24, 2023
@steveharter steveharter added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label Feb 24, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Feb 27, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Mar 15, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-DependencyInjection breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. bug help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant