2012-11-04 105 views
0

我在解决方案中有一个控制台项目和一个类库项目。库prject是我的数据访问层(DAL),我也在我的DAL中使用NHibernate和.NET Persistenc API。将配置添加到库项目C#

由于Iesi.Collections.dll需要NHibernate的,所以加载此组件(这是目前在我的控制台项目的bin文件夹)这是给我下面的错误:

An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information. 

但后来我加了以下配置到我的app.config文件,然后它成功加载了Iesi.Collections.dll。

<runtime> 
     <loadFromRemoteSources enabled="true" /> 
    </runtime> 

现在我已经设置了NUnit测试框架来测试我的DAL,为此我创建了一个新的类库项目。现在的问题是我在加载Iesi.Collections.dll时再次出现上面提到的错误。现在我需要将loadFromRemoteSources配置添加到我的测试项目中,以便通过网络加载程序集。但我的测试项目是一个库项目,所以我怎么能跟随配置文件的配置部分下面的行(因为类库项目没有任何配置文件)。

<runtime> 
     <loadFromRemoteSources enabled="true" /> 
    </runtime> 

更新:我加入了明确以下的app.config到我的测试项目(类库项目)

<?xml version="1.0"?> 
<configuration>  
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
    </startup> 
    <appSettings> 
     <add key="serviceUrl" value="test value" /> 
    </appSettings> 
    <runtime> 
     <loadFromRemoteSources enabled="true" /> 
    </runtime> 
</configuration> 

,我在我的两个测试项目,访问关键“的serviceUrl”值,以及如DAL使用的代码下面一行:

string strVal = System.Configuration.ConfigurationSettings.AppSettings["serviceUrl"]; 

但我仍是无法加载Iesi.Collections.dll,并获得相同的错误了。

回答