maartenba / MvcSiteMapProvider

An ASP.NET MVC SiteMapProvider implementation for the ASP.NET MVC framework.
Microsoft Public License
538 stars 218 forks source link

The SiteMapLoader has not been initialized. No DI. #447

Closed Menard85 closed 8 years ago

Menard85 commented 8 years ago

Hi, I've just updated MvcSiteMapProvider on the application I am working on from 3 to 4.

On my local machine, everything worked fine after the upgrade. But once I deploy my build to a remote environment to make further tests. I get the "The SiteMapLoader has not been initialized." error. In my case, 'MvcSiteMapProvider_UseExternalDIContainer' is set to false. I am using framework 4.5.1, and the package mentioned in the error is installed. I am using MVC4.

Every other posts about this error always mention Dependancy injections and they give me the impression that it's mandatory. The thing is that it works on my local machine with no issues so I don't think I need to install another package to make it work in another environment.

I tripled check the web.config on the remote machine, tripled checked I had the right packages in the bin folder (MvcSiteMapProvider.dll and the WebActivator one, both version 4.6.22).

I would prefer not having to add another package(DI) to an already complicated application, but if that's what I have to do I'll do it.

The error message I'm getting doesn't seem to apply, or maybe I am just missing something, being a rookie and all, it can happen.

NightOwl888 commented 8 years ago

Best guess is that it is due to the change in #342 - there is another dependent DLL MvcSiteMapProvider.WebActivator in the MvcSiteMapProvider.MVCx packages. This is the component that contains the WebActivator .NET attribute to auto-execute MvcSiteMapProvider.

Some people don't want a reference to WebActivator, so leaving out this package gives you the ability to remove the reference to that 3rd party library altogether. However, if you do, you need to add the following line to your Application_Start method in Global.asax (or Startup.cs) so MvcSiteMapProvider will launch.

MvcSiteMapProvider.DI.Composer.Compose();

So, you have 2 options:

  1. Add the missing MvcSiteMapProvider.WebActivator.dll reference
  2. Remove the reference to WebActivator and add the startup line to your project

This isn't usually an issue if you use the Publish feature of Visual Studio to properly compile and release your site with all of its dependencies. Most people use it, which is why there are rarely complaints of this issue.

Menard85 commented 8 years ago

Your best guess was the right one again. Thanks.