Skip to content

NullReferenceException on Unregister #390

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

Closed
eocron opened this issue Apr 1, 2021 · 3 comments
Closed

NullReferenceException on Unregister #390

eocron opened this issue Apr 1, 2021 · 3 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@eocron
Copy link

eocron commented Apr 1, 2021

Using unregister on keyed registrations result in NRE across all Resolve methods:
Version: all versions (tested on 2.* and 4.7.*)
Actual:

    [TestMethod]
    public void Repro()
    {
        var implementationType1 = typeof(A);
        var implementationType2 = typeof(B);
        var interfaceType       = typeof(ITargetInterface);
        var container           = new Container();
        container.Register(interfaceType, implementationType1, serviceKey: "foo");
        container.Register(interfaceType, implementationType2, serviceKey: "bar");

        container.Unregister(interfaceType, serviceKey:"foo");

        Assert.ThrowsException<ContainerException>(()=> container.Resolve(interfaceType, "foo")); //<---throws NRE
        container.Resolve(interfaceType, "foo", IfUnresolved.ReturnDefault); //<---throws NRE
        container.ResolveMany(interfaceType, ResolveManyBehavior.AsFixedArray);//<---throws NRE
    }

Expected:
Resolve with key with optional -> return default
Resolve with key - > throws ContainerException
ResolveMany for interface -> returns single registered service

PS:
Also throws on container.ClearCache(interfaceType);

@dadhi
Copy link
Owner

dadhi commented Apr 1, 2021

thanks, will look.

@dadhi dadhi closed this as completed in 5ba83d8 Apr 4, 2021
@dadhi dadhi self-assigned this Apr 4, 2021
@dadhi dadhi added the bug Something isn't working label Apr 4, 2021
@dadhi dadhi added this to the v4.7.5 milestone Apr 4, 2021
@dadhi
Copy link
Owner

dadhi commented Apr 4, 2021

The version v4.7.5 with the fix is out

@eocron
Copy link
Author

eocron commented Apr 6, 2021

Thank you!

yallie pushed a commit to yallie/DryIoc that referenced this issue Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants