Martin McMahon
Martin McMahon

Reputation: 333

Moving models to separate project

I'm trying to move my models to a separate project in my ASP.NET MVC 3 application. Everything work fine with the exception of one file where I get the error -

The type or namespace name 'Compare' could not be found (are you missing a using directive or an assembly reference?) The type or namespace name 'CompareAttribute' could not be found (are you missing a using directive or an assembly reference?)

The references in the new project are exactly the same as the references in the original MVC project but when this one file is moved to the new project it gives the errors above.

Any ideas what I am missing?

Upvotes: 0

Views: 993

Answers (2)

GUMatrix
GUMatrix

Reputation: 1

When adding a reference to a component/namespace it can be useful to expand or resize the Add Reference window to see all the additional column information, such as Version, Runtime and Path. In response to the above, you may had reference System.Web.Mvc prior to MVC 3 in which the CompareAttribute hadn't been introduced.

Try sorting the Component Name column and check for duplicate entries with different Version, Runtime and Path values. This can be true if you have more than one .NET Framework installed. Ensure that you choose the correct version that supports what you need. In this case selecting System.Web.Mvc Version 3.0.0.0 or above would have included the CompareAttribute that you were after.

Kind regards

Upvotes: 0

user596075
user596075

Reputation:

The CompareAttribute Class is part of the System.Web.Mvc namespace. Make sure you have that assembly as a reference in your project (in Solution Explorer -> References), and also make sure you have:

using System.Web.Mvc;

At the top of your source file.

MSDN Reference on the CompareAttribute Class:

Namespace: System.Web.Mvc
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)

Upvotes: 1

Related Questions