2010-05-27 35 views
33

任何想法,爲什麼我在我的MVC2項目中得到下面的錯誤,即使通過項目本身,我肯定有一個「system.Web.Entity」的引用?ASP.net頁面在導入語句中出錯,但我確實有參考嗎?

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" %> 

感謝

編輯 - 通過,如果我拿出3號線的方式,然後我得到的錯誤:

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 
+13

您是否在Web.config中引用了此程序集System.Data.Entity? (部分) – miensol 2010-05-27 06:56:55

+0

否 - 我只是將它添加到項目的引用部分 - 這是asp.net的問題嗎? – Greg 2010-05-27 07:00:35

回答

55

由於miensol建議,嘗試把這個在您的Web.config文件:

<compilation debug="true" targetFramework="4.0"> 
    <assemblies> 
    <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
    </assemblies> 
</compilation> 
+1

格雷格是問這個問題的人,信用應該去miensol。 – StarCub 2011-05-23 23:02:30

+0

優秀的解決方案! – imdadhusen 2011-06-28 12:16:22

+0

我有一個控制檯應用程序。在哪裏創建Web.config文件? (存在一個app.config文件) – Monish 2012-07-06 05:13:11

0

Monish,App.config文件的用途與Web.config相同文件和添加程序集的方式與爲Web.config文件完成的方式相同。

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

的替代與compilation.assemblies配置擺弄僅僅是爲了紀念System.Data.Entity的組件「複製本地」在您的解決方案。

這個工程由於根級別web.config含有wildcard add element,這會導致你的「私有集合緩衝區」所有程序集頁面編譯期間使用。從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).

+0

單獨向我的web.config文件(解決方案級別和視圖級別)添加程序集部分不起作用 - 我必須將引用屬性「Copy Local」更改爲「true」 - 謝謝施耐德 – Dudeman3000 2013-10-20 13:41:11

0

而且你在web.config中引用(如上所示),您必須: 驗證DLL文件在您的項目,例如BIN文件夾中。如果您想知道該DLL是否爲正確的版本,則必須到C:\ Windows \ Assembly並驗證您是否具有與您的項目對應的各自的PublicKeyToken的DLL版本。複製正確的DLL,但使用CMD(在Windows資源管理器中不顯示文件)執行此示例,鍵入CD C:\ Windows \ Assembly \ GAC_MSIL並複製所需的DLL。