2013-12-16 18 views
8

Aynı çalışma süresi içinde başka bir özel web projesi yüklemek için modüler bir MVC projesi oluşturdum.MVC: '~ /.../ dizininde görüntülenen' Index.cshtml 'oluşturulmadı

Diğer projeler "Modüller" adlı web sitesinin kökündeki bir klasörde bulunur. Alt dizinlerin içindeki diğer derlemeleri önyükleme sırasında yüklemek için PreApplicationStartMethod özniteliğini kullanıyorum.

Her bir modülü ad alanı kısıtlamalarıyla hedeflemek için özel yollar ekledim. -> ~/Modüller/ModuleTest/Görüntüleme ~/Görüntüleme/Ev/Index.cshtml:

Ben RazorViewEngine bir çağrı modülünde element için yapıldığında viewPath geçersiz kılmak için uygulayan bir sınıf oluşturmak zorunda /Home/Index.cshtml.

dinamik olarak yüklenen kütüphane içinde Endeksi() yöntemi başarıyla denilen ama görünüm işlendiğinde bir hata var olduğunu:

aşağıdaki resme bakın: http://i.imgur.com/KoTgxg2.png

çerçeve temelde söyle görünüm bulundu, ancak o render olmaz. Çerçevenin bunu neden oluşturmayı reddettiği konusunda herhangi bir fikri olan var mı?

'/' Uygulamasında Sunucu Hatası.

'~/Modules/ModuleTest/Views/Home/Index.cshtml' dosyasında bulunan görünüm oluşturulmadı.

Açıklama: Geçerli web isteğinin yürütülmesi sırasında işlenmeyen bir özel durum oluştu. Hata hakkında ve kodda nereden kaynaklandığı hakkında daha fazla bilgi için yığın izlemesini gözden geçirin.

Özel Durum Ayrıntıları: System.InvalidOperationException: '~/Modules/ModuleTest/Views/Home/Index.cshtml' dosyasında bulunan görünüm oluşturulmadı.

  • İstisna
 
Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 

[InvalidOperationException: The view found at '~/Modules/ModuleTest/Views/Home/Index.cshtml' was not created.] 
    System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +362 
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +431 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +39 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +116 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +529 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +106 
    System.Web.Mvc.Async.c__DisplayClass28.b__19() +321 
    System.Web.Mvc.Async.c__DisplayClass1e.b__1b(IAsyncResult asyncResult) +185 
    System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40 
    System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44 
    System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult, Controller controller) +39 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39 
    System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39 
    System.Web.Mvc.MvcHandler.b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +39 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70 
    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59 
    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40 
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9514812 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408 
  • Kontrolör

    public class HomeController : Controller 
    { 
     public ActionResult Index() 
     { 
      return View(new TestModel() { Value = "Bla" }); 
     } 
    } 
  • Görünüm
 

    @using Easily.ModuleTest.Models; 
    @{ ViewBag.Title = "Test Index"; } 
    @model TestModel 
    @Model.Value 

  • CustomRazorViewEngine

    public class CustomRazorViewEngine : RazorViewEngine 
    { 
     public CustomRazorViewEngine() 
     { 
      List tmpViewLocationFormats = new List(ViewLocationFormats); 
      List tmpMasterLocationFormats = new List(MasterLocationFormats); 
      List tmpPartialViewLocationFormats = new List(PartialViewLocationFormats); 
      foreach (string moduleDirectory in EasilyModulesContainer.Modules.Select(x => x.Directory)) 
      { 
       foreach (string viewLocationFormat in ViewLocationFormats) 
        tmpViewLocationFormats.Add(viewLocationFormat.Replace("~/", string.Format("~/{0}/{1}/", Constants.ModulesDirectory, moduleDirectory))); 
       foreach (string masterLocationFormat in MasterLocationFormats) 
        tmpMasterLocationFormats.Add(masterLocationFormat.Replace("~/", string.Format("~/{0}/{1}/", Constants.ModulesDirectory, moduleDirectory))); 
       foreach (string partialViewLocationFormat in PartialViewLocationFormats) 
        tmpPartialViewLocationFormats.Add(partialViewLocationFormat.Replace("~/", string.Format("~/{0}/{1}/", Constants.ModulesDirectory, moduleDirectory))); 
      } 
      ViewLocationFormats = tmpViewLocationFormats.ToArray(); 
      MasterLocationFormats = tmpMasterLocationFormats.ToArray(); 
      PartialViewLocationFormats = tmpPartialViewLocationFormats.ToArray(); 
     } 

     protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath) 
     { 
      return base.CreateView(controllerContext, GetPath(controllerContext, viewPath), masterPath); 
     } 

     protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath) 
     { 
      return base.CreatePartialView(controllerContext, GetPath(controllerContext, partialPath)); 
     } 

     private string GetPath(ControllerContext controllerContext, string path) 
     { 
      if (!controllerContext.RouteData.Values.ContainsKey("_module")) 
       return path; 
      Module module = ModulesContainer.Modules.SingleOrDefault(x => x.Name == controllerContext.RouteData.GetRequiredString("_module")); 
      return path.Replace("~/", string.Format("~/{0}/{1}/", Constants.ModulesDirectory, module.Directory)); 
     } 
    } 
+0

görünümünüzü hatasız geçerli: Yani modül için ilk searhing kod düzenlenebilir? –

+0

Derleme modu nedir? compilationMode değiştirmeyi =”Her zaman '? yardımcı olur mu –

+0

Bunu denemek ama onun değişmiyor şey maalesef – Lex2193

cevap

8

I http://aspnetwebstack.codeplex.com/ içine ayıklama sorunu bulundu.

Aslında denetleyicileri içeren kütüphaneyi ModulesContainer sınıfında (soruya bakın) kutudan başka bir klasörden yüklüyorum.Ama System.Web.Mvc.dlliçinde bir yöntem varsayılan dizininde bir assembly.load() yaparak benim denetleyicisi türünü bulmaya onun neden BuildManager.GetCompiledType() dönüş boş. Sadece benim önceden oluşturulmuş dll hafıza içerisindeki arıyorum

AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainAssemblyResolve;

ve

private static Assembly CurrentDomainAssemblyResolve(object sender, ResolveEventArgs args) 
    { 
     if (args.RequestingAssembly != null) 
      return args.RequestingAssembly; 
     Module module = _modules.SingleOrDefault(x => x.Assembly.FullName == args.Name); 
     if (module != null) 
      return module.Assembly; 
     throw new Exception(string.Format("Unable to load assembly {0}", args.Name)); 
    }

:

Birlikte bu yöntemi geçersiz kılmak için basit bir yol bulduk önceden yüklenmiş montajı bulun.

Lex2193 @
+2

Bu kullanışlı görünüyor, ancak _modules değişkeni nerede tanımlanmış ve doldurulmuş? – Jeremy

0

: Cevabını sorunu buldum. Ben başvurulan derleme varlığını dayandırdığı başka referansı vardır durumun haricinde iyi çalışıyordu kodunuzu kullanarak zaman:

Module [M] => Dependency [D] => DeepDependency [DD] 

sizden modül nesne kullanmak [D] diye içeri bazı aramalar sahip olduğunu [DD] içinde bir şey. TypeLoad istisnasında başarısız olur. Montaj talebi nedeniyle.

public static Assembly CurrentDomainAssemblyResolve(object sender, ResolveEventArgs args) 
{ 
    Assembly module = modules.SingleOrDefault(x => x.FullName == args.Name); 
    if (module != null) 
     return module; 

    if (args.RequestingAssembly != null) 
     return args.RequestingAssembly; 

    throw new Exception(string.Format("Could not load file or assembly {0}", args.Name)); 
} 
İlgili konular