From the stack trace it is clear that you are using the the Unity.Mvc4 NuGet package, which is some unofficial package and is not published by Microsoft. This package contains a bug. Its UnityDependencyResolver.ChildContainer
property calls HttpContext.Current.Items
without checking whether HttpContext.Current
is null and it causes a NullReferenceException
when instances are resolved outside the context of a web request.
So instead of using that unofficial NuGet package, I think you're better off using the official NuGet package.