Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net page gets error on import statement, but I do have the reference in place?

Any ideas why I am getting the below error in my MVC2 project, even through in the project itself I definitely have a reference to "system.Web.Entity"?

Compiler Error Message: CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)  Source Error:  Line 1:  <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<List<Node>>" %> Line 2:  <%@ Import Namespace="TopologyDAL" %> Line 3:  <%@ Import Namespace="System.Data.Entity" %> 

thanks

EDIT - By the way if I take out Line 3 then I get 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: CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.  Source Error:  Line 164:     Line 165:    [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()] Line 166:    public class views_node_index_aspx : System.Web.Mvc.ViewPage<List<Node>>, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler { Line 167:         Line 168:        private static bool @__initialized;   Source File: c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\6ec16fd2\a2147d7c\App_Web_index.aspx.1b64bdf1.ajruf7pv.0.cs    Line: 166  
like image 756
Greg Avatar asked May 27 '10 06:05

Greg


2 Answers

As miensol suggested, try putting this in your Web.config file:

<compilation debug="true" targetFramework="4.0">   <assemblies>     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />   </assemblies> </compilation> 
like image 121
Leo Moore Avatar answered Oct 08 '22 20:10

Leo Moore


The alternative to fiddling with the compilation.assemblies configuration is simply to mark the System.Data.Entity assembly as "Copy Local" in your solution.

This works due to the root-level web.config containing a wildcard add element, which causes all assemblies in your "private assembly cache" to be used during page compilation. From MSDN:

The value of the add element is an assembly name, not a DLL path. ASP.NET looks up the assembly name to find its physical DLL location. Optionally, you can specify the asterisk (*) wildcard character to add every assembly within the private assembly cache for the application, which is located either in the \bin subdirectory of an application or in the.NET Framework installation directory (%systemroot%\Microsoft.NET\Framework\version).

like image 44
Jack Ukleja Avatar answered Oct 08 '22 21:10

Jack Ukleja