Skip to content

ObjectFactory should verify against a null serviceProvider #82315

@steveharter

Description

@steveharter

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Extensions-DependencyInjectionbreaking-changeIssue or PR that represents a breaking API or functional change over a prerelease.bughelp wanted[up-for-grabs] Good issue for external contributors

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions