404 on Controllers in External Assemblies

感情迁移 提交于 2019-12-02 19:33:35

Turns out that this is a bug in Asp.Net itself.

After discussing the issue with Eilon Lipton of the Asp.Net team, and thinking this was something amiss in the MVC Framework, Eilon and a couple team members dug into things and found that the error was at a lower level per this conversation: http://aspnetwebstack.codeplex.com/discussions/403529

They also suggested a workaround that included another call on BuildManager after the call to AddReferencedAssembly, which I implemented via the following code:

    // Add the plugin as a reference to the application
    BuildManager.AddReferencedAssembly(assembly);
    BuildManager.AddCompilationDependency(assembly.FullName);

This allows you to add additional controllers/compiled views at startup in your pre-application init stage. What I'm doing now is looping through the list of DLLs in my plugins directory and pushing them to BuildManager as above.

The only limitation here is that you can't remove assemblies or clear the cache dynamically. The only way that I've found to do this is to add a previously unknown assembly to the referenced assemblies and compilation dependencies. I am experimenting with dynamically emitting a new assembly during pre-application initialization so that I can always, effectively, clear the cache and remove previously included plugins by faking a new assembly.

Hope this helps someone else out there.

Cheers.

It looks like this issue:

MVC uses assembly-qualified type name of the view engine to disambiguate view cache entries from different view engines. So it's not possible to have more than one PrecompiledMvcEngine object (as when you have precompiled views in more than one assembly). The problem can be solved by creating a different derived class from PrecompiledMvcEngine for each assembly. Or by creating a single generic derived class parameterized with some type from the assembly.

Article is here.

Felipe Miosso

@MisterJames, take a look at this:

Asp.Net Mvc Pluggable Application

I hope it's useful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!