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

Having issue iterating over collection, throws NRE #782

Closed
chrisagay opened this issue Dec 4, 2019 · 3 comments
Closed

Having issue iterating over collection, throws NRE #782

chrisagay opened this issue Dec 4, 2019 · 3 comments
Labels

Comments

@chrisagay
Copy link

@chrisagay chrisagay commented Dec 4, 2019

I am attempting to utilize a factory to generate which implementation to provide. I have registered the collection of interface implementations, and that is successfully passed to the constructor of the factory to be used when generating the proper implementation. I have tried using foreach, Where (LINQ) and SingleOrDefault with boolean function (LINQ).
In my case I have 2 implementations, and I can step through and get the information on first element. As the enumerator calls MoveNext( ) it throws an NRE. Can someone help explain what I might be doing wrong?

Thanks in advance!

@chrisagay chrisagay added the question label Dec 4, 2019
@dotnetjunkie

This comment has been minimized.

Copy link
Collaborator

@dotnetjunkie dotnetjunkie commented Dec 4, 2019

Hi @chrisagay,

Can you please provide the nessisary details for us to reproduce the issue? This means:

Anything that helps us to reproduce your issue would be, such as:

  • a complete stack trace including all exception details of the exception and all inner exceptions if an exception is thrown.
  • a Minimal, Complete, and Verifiable example that reproduces the problem. (see: https://stackoverflow.com/help/mcve)
  • Add any other context about the problem here. e.g.: Library versions (version of Simple Injector and all affected integration packages).
  • If you aren't using the latest version of Simple Injector, have you tried to reproduce the bug on the latest version of Simple Injector?
@chrisagay

This comment has been minimized.

Copy link
Author

@chrisagay chrisagay commented Dec 4, 2019

@dotnetjunkie

This comment has been minimized.

Copy link
Collaborator

@dotnetjunkie dotnetjunkie commented Jan 15, 2020

When a NullReferenceException is thrown from inside one of your constructors that is called by Simple Injector, the exception can be cryptic. This happens because Simple Injector constructs a single delegate with compiled code that creates a complete object graph of possibly many objects. This could make it unclear that the exception originates from your own code, especially if the exception originates from an instance initializer of your class, although the stack trace would give some clues.

Although it is technically possible to improve the exception information and wrap the original exception in a Simple Injector exception that explains that your type threw the exception, it is not feasible to achieve this without introducing a big performance penalty, because instead of having one single delegate that creates an entire graph, every creation of a single object must be wrapped in code that would catch any exception. This effectively means wrapping object creation in a new delegate, for every created object in the graph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.