I am having trouble resolving 404 responses in my Asp.Net MVC 4 project. It's built in VS2012 targeting 4.5.
I have pre-compiled views and controllers built into stand-alone DLLs. I am able to dynamically load the DLLs and inspect them from my core project, even invoke methods on them; however, it seems that the MVC Framework is not aware of the controllers. I am close here, but there is something missing.
Background on the Controllers and Views
Controllers are built in a stand-alone MVC project and inherit from Controller. Nothing too interesting going on there. The views use RazorGenerator and become classes that live in the project.
The output of the project is a DLL which correctly contains the controllers and views.
The DLLs implement a specific interface, we'll call it IPlugin, in a separate class (not part of a controller) in the library.
Loading the DLLs
Running as admin in Visual Studio I compile my app, which is hosted under IIS. With the project built, I drop a plugin DLL into my "Plugins" directory. Without debugging (this becomes important later), I open IE and navigate to the site. Note that at this point the App has been built, but never run, so startup events will fire. Everything here is still consistent if I recycle the app pool.
I have a Startup class with two methods, PreStart and PostStart and invoke the methods using WebActivator.PreApplicationStartMethod and WebActivator.PostApplicationStartMethod respectively.
PreStart is where I do the following:
- Get a list of all the plugin DLLs in my "Plugins" directory
- Copy all plugins to
AppDomain.CurrentDomain.DynamicDirectory - Load the type...if it contains an
IPluginI then- Add the assembly to the BuildManager
- Add the assembly to the BuildManager