structuremap/structuremap — pull request #304 by asbjornu (2014-10-30 08:40:58+00:00)
Title: SessionCache throws NullReferenceException in a nested container

I've not been able to reproduce this in a test, but given a rather complex plugin graph, I've discovered that resolving certain concrete, unregistered types, causes the `SessionCache` to throw a `NullReferenceException`.

This pull request tries to remedy this a bit by adding null-guards for all the objects that are involved in the given scenario. I've verified that these guards cause `ArgumentNullException` to be thrown instead, which is an improvement, but I've not been able to figure out the root of the problem yet.

The exception itself looks like this:
```
System.NullReferenceException occurred
_HResult=-2147467261
_message=Object reference not set to an instance of an object.
HResult=-2147467261
IsTransient=false
Message=Object reference not set to an instance of an object.
Source=StructureMap
StackTrace:
at StructureMap.SessionCache.GetDefault(Type pluginType, IPipelineGraph pipelineGraph) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\SessionCache.cs:line 43
```
After introducing the null-guards and catching the `ArgumentNullException` being thrown (with Debug > Exceptions in Visual Studio), I've managed to sew together this call stack:
```csharp
StructureMap.SessionCache.GetDefault(System.Type pluginType, StructureMap.IPipelineGraph pipelineGraph):line 42
StructureMap.BuildSession.GetInstance(System.Type pluginType):line 60
StructureMap.Container.GetInstance(System.Type pluginType):line 331
```
I wish I had a test case and a fix, but the plugin graph this happens on is so complex that it will take time to reproduce it. In the meantime I hope leaving this here might give someone an idea. In any case, all unit tests still pass, so merging these null-guards should be safe and an improvement anyway.