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.
For example, say you see a message that starts like:
None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Your.EncryptionService' can be invoked with the available services and parameters: Cannot resolve parameter 'Your.SecuritySettings securitySettings' of constructor 'Void .ctor(Your.SecuritySettings)'
In this case, Autofac is trying to create an instance of your service and it can’t resolve a constructor parameter it needs. Chances are you need to look at the things you have registered with Autofac and make sure you have something registered that can fulfill the constructor requirement. You could even verify this by manually trying to resolve the parameter yourself right from the container (in a test/debug environment). You may think you have it registered, but for whatever reason Autofac isn’t seeing the registration. (Autofac requires you explicitly register all services. Look at the Any Concrete Type Not Already Registered registration source if you don’t want to register everything.)
It may be that the top-level exception message doesn’t make sense, but that there are nested inner exceptions that have more information. Check those out! Creating big object graphs can sometimes yield a deep exception tree to help you pinpoint where exactly in the large graph things went wrong. Don’t just stop at the top level.
Also, take a look at your exception stack traces. It may look like Autofac is the source of an exception when really it’s getting caught by something going wrong in a constructor in one of your objects.
And, of course, if you’re hitting that ever-challenging
No scope with a Tag matching 'AutofacWebRequest' exception, we have a whole FAQ on that.
Symbols and Sources¶
Autofac publishes symbols and sources for its various packages on SymbolSource and MyGet. (Older packages are on SymbolSource, newer stuff has moved to MyGet.)
You can set up Visual Studio to debug/step right into Autofac source using the following symbol servers: