ASP.net page gets error on import statement, but I

2019-06-14 20:51发布

问题:

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 

回答1:

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>


回答2:

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).



回答3:

Monish, the App.config file serves about the same purpose as the Web.config file, and adding an assembly is done the same way as it is done for a Web.config file.

<configuration>
    <compilation debug="true">
        <assemblies> 
            <add assembly="myassembly, Version=1.0.0.0, Culture=neutral,PublicKeyToken=9999999999999"/> 
        </assemblies> 
    </compilation>
</configuration>


回答4:

Besides do you reference in web.config (as indicated above), you must: Verify that the DLL files are in your project, for example within the BIN folder. If you want to know if the DLL is the correct version must go to C: \ Windows \ Assembly and verify that you have here the DLL versions with their respective PublicKeyToken you against your project. Copy the correct DLL, but do it using CMD (in Windows Explorer does not show the files) example typing CD C: \ Windows \ Assembly \ GAC_MSIL and copy the DLL you need.