Using custom VirtualPathProvider to load inline views that inherit custom WebViewPage

Like this question, I use my own VirtualPathProvider to retrieve the views embedded in the DLL. If I do not put @inherits System.Web.Mvc.WebViewPage in my opinion, I get this error:

 The view at '~/Views/Home/Index.cshtml' must derive from ViewPage, ViewPage<TModel>, ViewUserControl, or ViewUserControl<TModel>. 

I am using a custom BaseViewPage that inherits from WebViewPage. Before I started using this custom VirtualPathProvider, the new base page in web.config worked. Now, if I try to inherit my own class on the page using @inherits My.BaseViewPage , I get the same error as above.

For completeness, I add that the page starts compiling if I inherit WebViewPage, but it throws an error because there is code expecting the view to have properties from BaseViewPage.

+4
source share
2 answers

Turns out the problem is with the view mechanism I used. To get VirtualPathProvider to work, I replaced the viewer with a custom one, which added the viewpoints I needed. I accidentally inherited from WebFormsViewEngine instead of RazorViewEngine , so the error I kept getting was for ViewPage instead of WebViewPage . Now that my entire sorted page with a basic view works very well.

+2
source

Hmmm ... is it possible that the base class cannot solve correctly from your DLL?

If so, you need to add a custom handler / resolver type to ... (from memory) AppDomain.AssemblyResolve - in this handler you will want to grab the corresponding type from your dll and return it back.

Pure guess, unfortunately - on my phone, so the research possibilities are limited.

+1
source

All Articles