Sporadic null reference exception on multiple instances of Web Api

27 views
Skip to first unread message

Prashanth Benny

unread,
Dec 20, 2016, 12:07:20 AM12/20/16
to Autofac
I am facing an issue currently using Web API for a website using Autofac which i need to connect to the cross platform app.

The code breaks when i call the API(only on multiple instances).

I have done enough of search on documentation, forums and on Stack Overflow. but there was no solution to my issue.

the code produces an exception at

var scope = EngineContext.Current.ContainerManager.Scope()  --Null reference exception

I have tried debugging the code but the exception is not generated regularly.

but i found some points where it breaks.

var sis = EngineContext.Current.Resolve<StoreInformationSettings>()
 
I have tried loading it once again, inside while statement as

var sis = EngineContext.Current.Resolve<StoreInformationSettings>()`
while(sis == null) 
{
    sis = EngineContext.Current.Resolve<StoreInformationSettings>()
}


var webHelper = EngineContext.Current.Resolve<IWebHelper>(); 

even in here, i did the same thing which worked again

var webHelper = EngineContext.Current.Resolve<IWebHelper>();
while(webHelper == null)
{
    webHelper = EngineContext.Current.Resolve<IWebHelper>();
and similarly, a few more instances. this suggests, it's loading but after a delay!

I have tried updating the Autofac Nuget package as instructed in some forum which failed again(i rolled back the version afterwards).

I am using MVC 4
Visual Studio 2015 
Autofac Version 3.5.2

this would be of great help, because I am currently stuck here. I cannot carry on further development because its breaking every now and then.
Thank you so much in advance for your help.

Travis Illig

unread,
Dec 20, 2016, 11:20:20 AM12/20/16
to Autofac
What is "EngineContext"? That's not Web API or Autofac.
Message has been deleted

Prashanth Benny

unread,
Dec 21, 2016, 2:18:49 AM12/21/16
to Autofac
Hello Travis, I am working on NopCommerce. Engine context is an interface to the AutoFac in nopcommerce.

Travis Illig

unread,
Dec 21, 2016, 11:36:26 AM12/21/16
to Autofac
You may need to post this to a NopCommerce forum. I don't think anyone here can tell you why you might get a null reference in a NopCommerce component. We don't have any official support or integration for NopCommerce, so if it's integrated, it's something they hooked up.
Reply all
Reply to author
Forward
0 new messages