views:

1472

answers:

10

Not entirely sure what's going on here; any help would be appreciated.

I'm trying to create a new .NET MVC web app. I was pretty sure I had it set up correctly, but I'm getting the following error:

The type 'System.Web.Mvc.ViewPage' is ambiguous: it could come from assembly 
'C:\MyProject\bin\System.Web.Mvc.DLL' or from assembly 
'C:\MyProject\bin\MyProject.DLL'. Please specify the assembly explicitly in the type name.

The source error it reports is as follows:

Line 1:  <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
Line 2:  
Line 3:  <asp:Content ID="indexContent" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">

Anything stand out that I'm doing completely wrong?

+1  A: 

This error usually indicates a class naming conflict. You are referencing two namespaces or you created a class with the same name in another namespace that you are using. I would start by looking at what that could be.

Dale Ragan
A: 

Dale, does it think I've created 'System.Web.Mvc.ViewPage' somewhere else in my project? I've looked for it, but found nothing.

Jordan H.
+1  A: 
 Inherits="System.Web.Mvc.ViewPage"

I'd imagine that this should be pointed at your View codebehind file class, not at the base ViewPage class.

FlySwat
+1  A: 

@Jordan H. - You are missing some of your audience w/o the asp.net-mvc tag on your question.

MotoWilliams
+2  A: 

Are you using a CodeBehind file, I don't see CodeBehind="" attribute where you are specifying the Inherits from? Then you have to point inherits to the class name of the codebehind.

Example:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="MvcApplication4.Views.Home.Index" %>

Make sure the Inherits is fully qualified. It should be the namespace followed by the class name.

Dale Ragan
A: 

MotoWilliams - Thanks, I added it. Jonathan - The particular page in question doesn't have a code-behind.

However, I closed Visual Studio and reopened it. The pages all seem to be working fine now. I'm pretty confused! Thanks everyone for the help.

Jordan H.
+2  A: 

I suppose you named one of your page "ViewPage" is that the case?

And like @Jonathan mentioned, this smells:

Inherits="System.Web.Mvc.ViewPage"

On my MVC application, all the view pages have this instead:

Inherits="MySite.Views.Pages.Home"

Or something along the line. Your aspx page markup should have "Inherits" point to your code-behind class name, not the actual class that it is inheriting. The attribute name is rather misleading but its an artifact of earlier days.

chakrit
+1  A: 

I'm running ASP.NET MVC Beta and also encountered this error.

It came about while I was trying to remove the code behind file for a view. I removed the "CodeBehind" attribute in the @Page directive and changed the "Inherits" attribute to point to System.Web.Mvc.ViewPage, but left the actual aspx.cs code behind file untouched in my project.

At this point, if I tried to run my project, I got the error you mentioned.

I resolved this error by deleting the aspx.cs (code behind) file for the view from my project.

Peter M
A: 

I had the same problem, closing visual studio and restarting solved it :)

Ami
A: 

Open up C:\MyProject\bin\MyProject.DLL in Reflector and look for ViewPage to see if you've defined one by accident.

Haacked