asp.net mvc - Strongly Typed View Not Found When Loading From External Library -


background

i have mvc 4 application trying fit pluggable architecture. loading dlls within areas directory named "vs.web.iportal.apps.*.dll".

problem

this working, except when using strongly-typed views. there troubleshooting or debugging methods can understand being done "find" view mvc routing engine looking for?

error @ bottom

code

here's code relevant i'm doing.

pluggableinterface.dll

a standard class library, 1 class applicationdynamicdiscovery.

properties/assemblyinfo.cs

[assembly: preapplicationstartmethod(typeof(applicationdynamicdiscovery), "discover")] 

applicationdynamicdiscovery.cs

public static class applicationdynamicdiscovery {             /// <summary>     /// discover dlls meet spec in path. static, happens     /// before startup - works.     /// </summary>     public static void discover()     {         var areasdir = new directoryinfo(system.io.path.combine(system.appdomain.currentdomain.basedirectory, "areas"));          if (!areasdir.exists)         {             return;         }          var assemblies = areasdir.getdirectories()                 .selectmany(d => d.getdirectories("bin", searchoption.topdirectoryonly))                 .selectmany(d => d.getfiles("vs.web.iportal.apps.*.dll", searchoption.topdirectoryonly))                 .select(f => assembly.loadfile(f.fullname));          // register assemblies.         assemblies.tolist().foreach(buildmanager.addreferencedassembly);     } } 

mainmvcapp main application doesn't have custom code - created using mvc 4 internet application template. create project reference pluggableinterface.dll.

mvcapp create project inside of areas folder of mainmvcapp.

mvcapparearegistration.cs

namespace vs.web.iportal.apps.mvcapp {     public class mvcapparearegistration : arearegistration     {         public override string areaname         {                         {                 return "mvcapp";             }         }          public override void registerarea(arearegistrationcontext context)         {             // default route             context.maproute(                     "mvcapp_default",                     "mvcapp/{controller}/{action}/{id}",                     new { action = "index", id = urlparameter.optional },                     new string[] { "vs.web.iportal.apps.mvcapp.controllers" }                 );         }     } } 

controllers/mvcappcontroller.cs

namespace vs.web.iportal.apps.mvcapp.controllers {     public class mvcappcontroller : controller     {         public actionresult index()         {             return this.view(new mvcappmodel { name = "test" });         }     } } 

models/mvcappmodel.cs

namespace vs.web.iportal.apps.mvcapp.models {     public class mvcappmodel     {         public string name { get; set; }     } } 

views/mvcapp/index.cshtml

@model vs.web.iportal.apps.mvcapp.models.mvcappmodel  <h2>title - @model.name </h2> 

with in place - can start server , browse localhost:port/mvcapp/mvcapp receive following error

the view 'index' or master not found or no view engine supports searched locations. following locations searched: ~/areas/mvcapp/views/mvcapp/index.aspx ~/areas/mvcapp/views/mvcapp/index.ascx ~/areas/mvcapp/views/shared/index.aspx ~/areas/mvcapp/views/shared/index.ascx ~/views/mvcapp/index.aspx ~/views/mvcapp/index.ascx ~/views/shared/index.aspx ~/views/shared/index.ascx ~/areas/mvcapp/views/mvcapp/index.cshtml ~/areas/mvcapp/views/mvcapp/index.vbhtml ~/areas/mvcapp/views/shared/index.cshtml ~/areas/mvcapp/views/shared/index.vbhtml ~/views/mvcapp/index.cshtml ~/views/mvcapp/index.vbhtml ~/views/shared/index.cshtml ~/views/shared/index.vbhtml  

if remove @model vs.web.iportal.apps.mvcapp.models.mvcappmodel view works. if remove reference pluggableinterface project , add mvcapp project works typed model. can point me how troubleshoot routing issue appreciated.

i resolved keeping track of assemblies after i've added them, , adding assembly resolver. don't know if it's best solution, seems trick.

appdomain.currentdomain.assemblyresolve += currentdomainassemblyresolve; applicationdynamicdiscovery.assemblies = new list<assembly>(); 

currentdomainassemblyresolve function:

    /// <summary>     /// through dynamically loaded assemblies, when looking assembly.     /// </summary>     private static assembly currentdomainassemblyresolve(object sender, resolveeventargs args)     {         if (args.requestingassembly != null)         {             return args.requestingassembly;         }          // might return null         return applicationdynamicdiscovery.assemblies.singleordefault(x => x.fullname == args.name);     } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -