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:WindowsMicrosoft.NETFramework64v2.0.50727Temporary ASP.NET FilesGrowOpMgr9ce518196bc1e534assemblydl3e30b5990f8ba0707_929ac901GrowOpMgr.Web.DLL' and 'c:WindowsMicrosoft.NETFramework64v2.0.50727Temporary ASP.NET FilesGrowOpMgr9ce518196bc1e534assemblydl327c4ec241860e2f_d595c901System.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:WindowsMicrosoft.NETFramework64v2.0.50727Temporary ASP.NET FilesGrowOpMgr9ce518196bc1e534App_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