First off, you should be commended for trying to research your problem and for including some info about things you tried and that didn't work. But in spite of your hard work, I still see some fairly major problems with the question.
- On the first read, my immediate gut reaction is, "technology soup." Someone who doesn't immediately recognize everything you're using is going to struggle making sense of it. Most users are probably going to have to go look up at least one of these technologies.
- The English doesn't flow very well. Combined with the above, this makes it difficult or at least time consuming to understand the issue.
There's a good amount of fluff that could be removed without changing anything about the question. Some examples:
The code breaks when i call the API.
I have done enough of search on NopCommerce documentation, forums and on Stack Overflow. but there was no solution to my issue.
maybe it comes and sometimes not.
Your problem is hard. This line jumps out at me:
I have tried debugging the code but the exception is not generated regularly
This means you have a heisenbug. The inability to reproduce the bug on demand adds an order of magnitude to the difficulty in solving it. It could also mean that other users can't reproduce it if it requires a slow network connection or something else in their environment.
There's no straightforward way to put together a compilable solution to test with. I'm not sure you can narrow this down much more, but even if you can't, it's not clear what things I need in my solution to build something that will reproduce your problem. Try to narrow this down. A simple MVCE that can be copy/pasted into a main method is the best, but should make it as easy as possible for any random strange to compile some code and see the issue.
The issue isn't completely clear. Okay, yes, you get null ref exceptions. At what point? When launching the site? When accessing an endpoint? A stack trace might go a long way to helping clarify this, but you should also make it explicit.
All this means that this question is going to be a time sink, and answerers have limited time. This is because of the combined difficulty in understanding, reproducing, and solving your problem. We'd generally rather spend our time on questions we are pretty confident we can come up with a solution for. Don't misunderstand; hard questions are perfectly fine. But also understand that not as many people are going to have the time on their hands to help with them.
So the key is to spend some time on providing things that speed up answers' ability to help. Here are some steps you should take:
Create an MVCE, or as close to one as you can. This is kind of involved, so I'll break it down some.
- Create a solution that reproduces the problem with only the technologies you mention.
- Now cut out as many technologies as you can without making the error go away. Replace Autofac with something quick and dirty. Replace WebAPI with something quick and dirty. If possible, cut out the fact it's a website entirely (i.e., create a command line MVCE instead). It doesn't need to fully work. It just needs to demonstrate the problem. And the fewer technologies are in your example, the closer you are to having the solution yourself and the closer someone else is to helping you track it down.
- Now try to make it reproduce the error consistently. It'll be a whole lot easier for anyone to help if they only have to run it once to see the error happen.
- Make it clear in the question what is needed to reproduce. I should be able to follow a couple of steps and have a fully running code base that throws the error you're getting. If I need NuGet packages installed, make that clear. If there are a lot of them, go back and remove as many as you can. If you still have a lot of them, I might suggest just including the contents of a
packages.config
file so I can drop it into my project and run. But whatever I need to run this code should be very clear and simple. Any more than 2 or 3 steps plus copying your code is too much.
Make the error very clear before you get into things you tried and what didn't work. Include a brief description and a stack trace.
Remove any content that doesn't help explain the problem or indicate things that didn't work for you. It saves your readers' time if they don't have to figure out what's important and what's not.
Along the way, you might figure out the problem yourself. Great! It's a success to solve your own problem. But until you've narrowed things down some more, it's going to be pretty hard for anyone else to help you, either.