Debugging and Troubleshooting
If you’re really having trouble and you haven’t been able to get an answer on StackOverflow you may want to try doing a little more in-depth debugging/troubleshooting on your own. Here are some tips on doing that.
The exceptions generated by Autofac really try to point you in the right direction with respect to what could be going wrong.
Don’t panic! Stop and read what it’s actually telling you. Here are some tips for reading Autofac exceptions that can save you a lot of time:
Read the whole message. Exceptions are usually pretty specific and will tell you exactly the thing that’s missing or wrong. Unfortunately, being specific means it’s hard to be short. Don’t skim the message, actually read it!
Look at inner exceptions. In large object graphs, sometimes the thing that failed is way down the stack. Autofac will try hard to bubble the important stuff up to the top, but sometimes it just isn’t possible. Be sure to look at inner exception messages - they’re not just noise!
Be aware of the stack trace. In some cases it may _appear_ that Autofac is the cause of the error, but the problem is in some constructor logic or a delegate that you registered. Follow the whole stack trace to find the exact location of the problem.
We have some documentation here on the most common exceptions and things to look for to fix them:
Autofac 6.0 introduced diagnostics support in the form of System.Diagnostics.DiagnosticSource. This allows you to intercept diagnostic events from Autofac.