2

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?

Community
  • 1
  • 1
Redeemed1
  • 3,953
  • 8
  • 38
  • 63
  • Take a look at the following link: http://shazwazza.com/post/Developing-a-plugin-framework-in-ASPNET-with-medium-trust It addresses the issue of having a strongly typed view with model type located outside of the bin. – Ilija Dimov Sep 14 '15 at 11:48
  • Thanks @Ilija Dimov that was very helpful. I can now make the assemblies load from the Plugins folder as desired. As the comments on the post indicate this will still require the app pool to be restarted but in my case while that would have been ideal this is still a workable solution because it means the bin folder is not polluted. Many thanks. I'll write up an answer to the question and give you credit for it. – Redeemed1 Sep 15 '15 at 08:58

2 Answers2

0

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

Kudos and thanks to @Ilija Dimov

Community
  • 1
  • 1
Redeemed1
  • 3,953
  • 8
  • 38
  • 63
0

Thought I should share my experience with dealing with the issue of strongly typed views when it comes to MEF. It's better not to use them if creating plugins. Use other front-end tools like knockout js to do databinding to views, which means you won't be using razor code at all, but it still gives you a good framework to build plugins on. To complement your plugins even more, use ko components, which promotes modularity and reusability at the same time.