Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

MVC ViewPage Compile Error, or “How to exist in both places”

This post is here for informational purposes only and is meant to be hit by users searching for a specific error. If you are reading this in your RSS reader, I apologize in advance for forcing you to read this far.

The context: An MVC application using what I believe is RC1 of ASP.NET MVC and Sharp Architecture.

The error:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0433: The type ‘System.Web.Mvc.ViewPage<HoochBase>’ exists in both ‘c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\GrowOpMgr\9ce51819\6bc1e534\assembly\dl3\e30b5990\f8ba0707_929ac901\GrowOpMgr.Web.DLL’ and ‘c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\GrowOpMgr\9ce51819\6bc1e534\assembly\dl3\27c4ec241860e2f_d595c901\System.Web.Mvc.DLL’
Source Error:

Line 170:    
Line 171:    [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
Line 172:    public class views_hooches_index_aspx : System.Web.Mvc.ViewPage<IEnumerable<HoochDto>>, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler {
Line 173:        
Line 174:        private static bool @__initialized;

Source File: c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\GrowOpMgr\9ce51819\6bc1e534\App_Web_index.aspx.9399a72b.8jtr0zsp.0.cs    Line: 172


The cause

I had created a view page without the aid of the MVC templates. I.e. I added a regular Web Form and manually changed the Inherits attribute in the Page directive at the top to System.Web.Mvc.ViewPage<HoochBase> like so (notice I also deleted the CodeBehind and AutoEventWireup attributes):

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<HoochBase>" %>

That is, I want to derive from the ViewPage<T> class, not from the code-behind. But I forgot to delete the code-behind files that were created by the Web Form template. I can only guess at what’s happening behind the scenes.

Note that if you do the same, this compilation error will occur on every MVC-based page, not just the one you created.

I imagine this doesn’t occur when you create an MVC View Page directly from the Add New Item dialog but I don’t have those templates. Installing them requires one of the following:

  • Running the msi package for MVC
  • Extracting the templates from the msi package and installing them manually

I don’t want to do the first because it installs MVC in the GAC which I absolutely do not want given the number of MVC apps I have lying around my machine using various versions of the framework. As for the second, I’m lazy, okay? YOU’RE NOT MY MOTHE—actually, I probably shouldn’t make that claim…

Would be nice if the MVC templates for creating view pages and view user controls were available outside of the .msi but it’s not hard to create pages/user controls without them.

Except when you get compilation errors, I suppose.

Kyle the Runtimed

This entry was posted in ASP.NET MVC, S#arp Architecture. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://mattcalla.com mattcalla

    I’m glad to see the “How to” titles are back. Good stuff!

  • pete w

    I read more closely and now I see what you mean about those templates.

    I just checked codeplex and just like you I couldnt find the templates in the source, they only seem to come bundled in the MSI.

    Yes the RC1 finally got rid of the code-behind, but I suppose that youre right; for now it takes some work to get the project templates without getting kicked in the GAC.

  • Kyle Baley


    I have no problem getting hold of the DLLs. The latest ones are already included in Sharp Architecture which is what I’m using to build MVC apps these days. Before that, I went with door 3 and built them from scratch.

    The part I sniped about was that in order to get the project/item templates, I need to run the MSI. Your options 1 and 2 will allow me to get my hands on those templates without having MVC in the GAC but it’s a lot of work to go through just to get the MVC templates, which aren’t all that useful in the first place. Sharp Architecture has a much better project template which means I’d just need the MVC templates to create view pages and view user controls. Given that they are just regular web forms/user controls with a modified Page directive, I don’t see a reason to bother.

    And last I checked, the CodePlex source didn’t include the item templates, yesno? Has that changed?

  • http://www.acceptedeclectic.com pete w

    I’m a fan of your writing.

    You can do one of three things if you really want those DLLs in your hands and out of the GAC.

    1. you could try to extract them out of the MSI http://thebackroomtech.com/2007/08/23/howto-extract-files-from-a-msi-file-using-the-windows-command-line/

    2. pull that DLL out of the GAC:

    3. download the source code for MVC from codeplex and build it!

    I dunno maybe these were not the clean answers you were envisioning, but I took the 2nd route when I had a similar need.