TargetInvocationException while trying to load an EPiServer CMS 6 site
A strange and not that clear error that I experienced while trying to load an EPiServer CMS 6 site setup on my computer. After some digging I found that the problem in my case was...
I though I'd just write this down since it wasn't the first time I experienced it and it seems like other people has encountered the same problem as well. Since the error message is somewhat unclear I though I better keep the solution or at least a hint to the solution close if it would ever happen again.
Database and missing files were causing the TargetInvocationException in my case!
Anyway the error got thrown during the initialization process of the site. Nothing to debug or check in any other way. Normally these errors are either super simple to solve or incredible hard. This scenario was very simple - Didn't have access to the database! Well that was the first error. The second and real problem was something the Ted helped me with and yes it was super simple. Make sure that all referenced/used system files are actually in the project! Sometimes it's so close that you don't see the real problem by your self. So what you need is two sets of eyez!
Another tip: to avoid this is when restoring a database, make sure that the user that you want to use really is setup correctly. When doing a restore the security settings might get a little bit messed up. What I normally do is remove the user from the database in question and the re-adds it directly.
Related issue that could cause the similar and somewhat unclear error message is if you have forgotten to setup the local VPPs correctly. Missed the rights of the application identity or just forgot to setup the folders. So make sure you check that as well.
Below you can read the complete error message, sorry about the fact that it is in Swedish.
Object reference not set to an instance of an object.
Beskrivning: Ett undantag som inte kunde hanteras uppstod när den aktuella webbegäran kördes. Mer information om felet och var i koden det uppstod finns i stackspårningen.
Undantagsinformation: System.NullReferenceException: Object reference not set to an instance of an object.
[Inga relevanta källrader]
Källfil: c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\2c9b2c38\70be6bce\App_global.asax.2ekmf0zi.0.cs Rad: 0
[NullReferenceException: Object reference not set to an instance of an object.]
EPiServer.Data.DataInitialization.Initialize(InitializationEngine context) +66
EPiServer.Framework.Initialization.InitializationEngine.Initialize(HostType hostType) +115
EPiServer.Framework.Initialization.InitializationModule.StaticInitialization(HostType hostType) +227
EPiServer.Framework.Initialization.InitializationModule.FrameworkInitialization(HostType hostType) +53
ASP.global_asax..ctor() in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\2c9b2c38\70be6bce\App_global.asax.2ekmf0zi.0.cs:0
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +146
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +298
System.Activator.CreateInstance(Type type, Boolean nonPublic) +79
System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object args, CultureInfo culture, Object activationAttributes) +10362891
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +258
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +382
[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11305670
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +88
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4342340