Jordan H.
Jordan H.

Reputation: 457

.NET MVC Ambiguous Type Reference

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?

Upvotes: 4

Views: 7836

Answers (9)

Don P
Don P

Reputation: 539

I had the same exact error this week.

My Webform.aspx file had a generated designer.cs file. In this file the class was actually named "ViewPage". Delete the designer file, or move the class contents to the webform.aspx.cs file and my error was gone.

Just putting it out there in case someone had this error.

Upvotes: 0

Paul
Paul

Reputation: 41

Check your assembly references to System.Web.Mvc in web.config.

Mine were explicitly specifying 2.0.0.0, but my project referenced 3.0.0.0

Upvotes: 2

Haacked
Haacked

Reputation: 59041

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

Upvotes: 1

Peter M
Peter M

Reputation: 472

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.

Upvotes: 2

chakrit
chakrit

Reputation: 61558

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.

Upvotes: 3

Dale Ragan
Dale Ragan

Reputation: 18270

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.

Upvotes: 2

FlySwat
FlySwat

Reputation: 175723

 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.

Upvotes: 1

Dale Ragan
Dale Ragan

Reputation: 18270

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.

Upvotes: 1

Related Questions