4

Similar to this question I am using a custom VirtualPathProvider to retrieve views that are embedded in dlls. If I don't put @inherits System.Web.Mvc.WebViewPage on my view I get this error:

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

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

For completeness' sake I'll add that the page does start to compile if I inherit from WebViewPage, but it throws an error because there is code expecting the view to have properties from BaseViewPage.

Community
  • 1
  • 1
ashanan
  • 121
  • 9

2 Answers2

2

It turns out that the problem had to do with the view engine I was using. To get the VirtualPathProvider working I replaced the view engine with a custom one that added view locations I needed. I accidentally inherited from WebFormsViewEngine instead of RazorViewEngine which is why the error I kept getting was for ViewPage instead of WebViewPage. Now that that's all sorted out my custom base view page works just fine.

ashanan
  • 121
  • 9
1

Hmmm...is it possible the base class it's failing to resolve properly from your dll?

If that is the case, what you need to do is add a custom assembly/type resolver handler on...(going from memory) AppDomain.AssemblyResolve - in that handler, you'll want to grab the appropriate type from your dll and return that back.

Purely a guess, unfortunately - on my phone, so research capabilities are limited.

JerKimball
  • 16,584
  • 3
  • 43
  • 55
  • Thanks for answering. I almost went down this route, but the [solution](http://stackoverflow.com/a/11057293/216553) turned out to be a simple instance of PEBKAC. – ashanan Jun 15 '12 at 19:51