2009-01-21 97 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