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

CanGetInstance throws System.ArgumentNullException when called with an unregistered serviceType and null serviceName #578

Closed
mesakomarevich opened this issue Oct 23, 2022 · 1 comment

Comments

@mesakomarevich
Copy link
Contributor

mesakomarevich commented Oct 23, 2022

As stated in the title, calling CanGetInstance(serviceType, serviceName) where serviceType has not yet been registered and serviceName = null will result in a System.ArgumentNullException.

This problem occurs with LightInject version 6.4.0-6.6.1

Stack trace is as follows:

System.ArgumentNullException: Value cannot be null. (Parameter 'key')
   at System.ThrowHelper.ThrowArgumentNullException(String name)
   at System.Collections.Concurrent.ConcurrentDictionary`2.TryGetValue(TKey key, TValue& value)
   at LightInject.ServiceContainer.GetRegisteredEmitMethod(Type serviceType, String serviceName)
   at LightInject.ServiceContainer.GetEmitMethod(Type serviceType, String serviceName)
   at LightInject.ServiceContainer.CanGetInstance(Type serviceType, String serviceName)

I will be creating a PR with a fix ASAP.

mesakomarevich added a commit to mesakomarevich/LightInject that referenced this issue Oct 23, 2022
…no registrations for the specified serviceType are found.
seesharper added a commit that referenced this issue Oct 23, 2022
Fixed issue #578 by setting serviceName to string.Empty if no registrations for the specified serviceType are found.
@mesakomarevich
Copy link
Contributor Author

Closing this issue as a resolution was merged long ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant