2009-01-21 74 views
5

我在BIN文件夾一個DLL,我需要它在web.config中引用,或我得到那個煩人的錯誤:如何在web.config中引用DLL?

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: CS0234: The type or namespace name 'ServiceModel' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

此DLL是不是在GAC,併爲我不能使用

<assemblies><add ... 

所以我的猜測是,我需要使用configSections像

<configSections> 
    <section name="Microsoft.System.Web" 
      type="Microsoft.System.Web, 
       Version=3.0.0.0, Culture=neutral, 
       PublicKeyToken=10633fbfa3fade6e "/> 
</configSections> 

什麼應該是正確的代碼?

回答

2

除非您使用的程序集是強命名的,否則將它放在bin目錄中是您所需要做的。

您提到的configSection不適用於添加對程序集的引用。這是爲了在web.config中定義配置部分。因此,您可以添加一個名爲exampleSection的配置節,方法是在configsSections中添加一個節標記。這將允許您稍後在web.config中創建一個名爲「exampleSection」的配置節。

在configSections部分定義中有一個程序集引用的原因是每個配置部分都是特定於它提供配置數據的程序集的。 configSection可能特定於網站程序集本身(在這種情況下,這是您要指定的程序集),也可能是網站使用的其他程序集。創建一個configSection使您能夠對一個部分中相關的設置進行分組,而不是在appsettings中將所有應用程序混合在一起。

如果您提供了有關您遇到麻煩的更多信息,也許我們可以提供幫助。什麼是裝配,它是如何使用的?

0

有趣的是,我發現如果dll及其所有依賴項位於bin目錄中,即使不在.SLN文件或web.config中,也可以使用它。

+0

Nop ...它只能工作,因爲它會從GAC獲取DLL。 :) - 如果你沒有它,那麼你會得到錯誤,如果沒有引用它在web.config – balexandre 2009-01-21 02:32:04

+0

我保證你的dll不在gac中。 – Joshua 2009-01-24 17:45:06