Question

Some Context

I have one closed source asp.net MVC application distributed for several customers. I'm trying to develop a extension to include some very specific functionalities that will be used by a single customer (he will also have the extension source code).

I'm developing the extension as another mvc project, loaded as an area. I'm trying to avoid having to deploy the extension binaries in the main application '/bin' folder.

I'm loading the extension assembly and it's dependencies manually in the PreApplicationStartMethod of the main application assembly. The area registration process went fine and the area routes are registered as intended.

The Problem

When I try to load some extension pages, I got a "The view 'xx' or its master was not found or no view engine supports the searched locations." message. I investigated I little and replaced the view contents with a 'Hello' string. The view was rendered correctly.

I tried to produce a minimal that triggers the error and turns out it's the '@model'directive. I tried to figure out what's happening and It's an assembly loading error. I created a minimal view with '@model object' and tried to cast the Model to original type and got the following error message: "Could not load file or assembly 'xxx' or one of its dependencies. The system cannot find the file specified." (this assembly contains the class type used by the view)

Just to confirm the issue, I moved the mentioned assembly to the main application '/bin' folder and everything worked.

I also inserted some model manipulation instructions on the controller, just to investigate if an exception will appear but everything went fine, I could even render a grid using json.

I'm loading every assemly with:

var assembly = Assembly.LoadFrom(file)
BuildManager.AddReferencedAssembly(assembly)

There's something extra I need to do ?

Was it helpful?

Solution

Needed to add the assembly private path

AppDomain.CurrentDomain.AppendPrivatePath(pluginFolder);

Don't know the real explanation for it but I guess it's relates to the use of Assembly.LoadFrom(file) instead of Assembly.Load() and the fact that views are compiled later.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top