Question

I have a Console project and a Class library project in solution. Library prject is my Data Access Layer (DAL), also I am using NHibernate and NET Persistenc API in my DAL.

As Iesi.Collections.dll is required for NHibernate, so while loading this assembly (which is present in my Console project's bin folder) it was giving me following error:

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.

But then I added following config to my app.config file and then it loaded Iesi.Collections.dll successfully.

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

Now I have setup NUnit test framework to test my DAL, and for this I have created a new Class library project. Now the problem is I am again getting above mentioned error while loading Iesi.Collections.dll. Now I need to add loadFromRemoteSources config to my test project to enable loading of assembly over the network. But my test project is a library project so how can I following lines under configuration section of config file (as Class library project does not have any config file).

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

UPDATE: I have added following app.config explicitly to my test project (Class library project)

<?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>

And I am to access key "serviceUrl" value in both my test project as well as DAL by using following line of code:

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

But still I am not able to load Iesi.Collections.dll, and getting the same error as before.

Was it helpful?

Solution

Is the file really loaded from network, or do you need to circumvent a different annoying security ceremony: http://www.hanselman.com/blog/RemovingSecurityFromDownloadedPowerShellScriptsWithAlternativeDataStreams.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top