2012-11-04 106 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,並獲得相同的錯誤了。

回答