1

I am getting an exception -

 System.NullReferenceException: Object reference not set to an instance of an object.

Result StackTrace:

   at System.Web.WebPages.FileExistenceCache.<.ctor>b__4(String path)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at System.Web.WebPages.FileExistenceCache.FileExists(String virtualPath)
   at System.Web.Mvc.BuildManagerViewEngine.FileExists(ControllerContext controllerContext, String virtualPath)

This exception is received when i try to test my custom view engine using mocked context. I was earlier getting another error, and came to this error after properly mocking the server.MapPath. The issue is in the mocked httpcontext, and want to know what may be the reason for having this exception only on unit test with mocked httpcontext. I dont have any issues in actual running code of the custom view engine which I am trying to test.

MGR
  • 303
  • 3
  • 14
  • 1
    I have updated the question more specific intention. It is not for knowing how to fix a null reference. – MGR Feb 18 '15 at 09:49
  • 1
    It may be that `HttpContext.Current` is empty. The `VirtualPathProviderViewEngine`, inexplicably, uses `HttpContext.Current` instead of the controller context's `HttpContext` in some places. I'm not sure what to do about that; I'll write up an answer if I find out more. – Paul d'Aoust Jun 17 '15 at 21:38

0 Answers0