Search code examples
c#asp.net-mvc-4razormef

ASP.Net MVC Views using a model type that is loaded by MEF result in JIT Compile error in the View builder


This is named to be similar to the following question : ASP.NET MVC: Views using a model type that is loaded by MEF can't be found by the view engine

which is a very similar problem to what I have. I am using .NetFx 4.6, MEF 2 and MVC 4. I have a separate class project that contains Mvc Views, related config in the Views folder and an Exported Model which is referenced in the View.

The View and related config along with the resulting dll are copied to a Plugins folder in an MVC Host project and all works except for when the View is compiled at runtime when I get the following error CS0234: The type or namespace name 'Central' does not exist in the namespace 'MyCompany' (are you missing an assembly reference?)

When I remove the Model reference in the View it will load the view correctly.

When I place the dll in the bin folder of the Host application it works well.

It is only when the dll is placed in the Plugins folder that this exception occurs.

I have tried to use the deprecated AppDomain.CurrentDomain.AppendPrivatePath(Path.Combine(HttpRuntime.AppDomainAppPath, "Plugins")); at the beginning of Global.asax Application_Start but this does not appear to help.

The referenced question has comments by @BradWilson and @MatthewAbbott both of which refer to the location of the dll in the bin folder.

Can anyone tell me how to do this such that the Imported dll may stay in a Plugins folder rather than having to put it into the bin folder and cause the MVC Host to reset?


Solution

  • In the end I used the solution referenced in @Ilija Dimov's comment and found here.

    Kudos and thanks to @Ilija Dimov