Skip to content

ObjectFactory should verify against a null serviceProvider #82315

Closed

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.

Activity

  1. added this to the 8.0.0 milestone on Feb 17, 2023
  2. modified the milestones: 8.0.0, Future on Feb 24, 2023
  3. ghost added
    untriaged
    on Feb 24, 2023
  4. added
    help wanted
    on Feb 24, 2023
  5. ghost removed
    untriaged
    on Feb 24, 2023
  6. added
    breaking-change
    on Feb 24, 2023
  7. ghost added
    in-pr
    on Feb 27, 2023
  8. ghost removed
    in-pr
    on Mar 15, 2023
  9. ghost locked as resolved and limited conversation to collaborators on Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Extensions-DependencyInjectionbreaking-changebughelp wanted

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions