Cannot run nunit-console from networked drive on unit-tests built with .Net 4

180 views
Skip to first unread message

Joel

unread,
Sep 27, 2010, 6:39:23 PM9/27/10
to NUnit-Discuss
Hi,

We have nunit (version 2.5.7) installed on a network share which is
mapped to J: drive. We do this to keep our build scripts etc. as
independent of individual developer machines as possible.

This has worked well in the past with unit test assemblies
targeting .Net 2.

However, on upgrading to .Net 4 (and upgrading to nunit version 2.5.7)
and running nunit console as follows :

nunit-console.exe /framework=4.0.30319 d:\ATLASCommon\source\Utilities
\TestUtilities\bin\Release\TestUtilities.dll

I get the following error :

NUnit version 2.5.7.10213
Copyright (C) 2002-2009 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A.
Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment -
OS Version: Microsoft Windows NT 5.1.2600 Service Pack 3
CLR Version: 2.0.50727.3615 ( Net 2.0 )

ProcessModel: Default DomainUsage: Single
Execution Runtime: v4.0.30319
Unhandled Exception:
System.IO.FileLoadException: Could not load file or assembly 'file:///
J:/BitBucket/Joel/nunit-test/nunit.core.DLL' or one of its
dependencies. Operation is not supported. (Exception from HRESULT:
0x80131515) File name: 'file:///J:/BitBucket/Joel/nunit-test/
nunit.core.DLL' ---> System.NotSupportedException: 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.

For some reason the assembly 'nunit.core.DLL' will not load from the
networked drive?

With .Net 2 we needed to use caspol.exe to enable full trust on our
networked (J:) drive in order to use assemblies on this drive.

After reading the link in the error message and also this article :

http://blogs.msdn.com/b/shawnfa/archive/2009/06/08/more-implicit-uses-of-cas-policy-loadfromremotesources.aspx

I tried enabling the loadFromRemoteSources switch but this did not
work (see Note 1 below).

Notes :
1. I have modified the nunit-console.exe.config is as follows :
<configuration>
<startup>
<requiredruntime version="v4.0.30319"> </requiredruntime>
</startup>
<runtime>
<loadFromRemoteSources enabled="true" />
</runtime>
</configuration>

2. If the nunit-console.exe is on a local drive then it runs fine.

3. If the unit test assemblies are built targetting .Net 2 then the
tests run fine.


Any ideas would be much appreciated.

Thanks in advance,
Joel Gordon.

Charlie Poole

unread,
Sep 27, 2010, 7:10:10 PM9/27/10
to nunit-...@googlegroups.com
Hi Joel,

I'm afraid I don't have a solution for you. NUnit has never actually
supported running from a network drive or loading tests from a
network drive although various community approaches to making
each of these work have evolved over time.

This limitation will probably be removed in NUnit 3.0 but the
changes needed are too deep to try in NUnit 2.x.

Charlie

> --
> You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
> To post to this group, send email to nunit-...@googlegroups.com.
> To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
>
>

Joel

unread,
Sep 27, 2010, 11:30:53 PM9/27/10
to NUnit-Discuss
Hi Charlie,

Thanks for the prompt reply. I think I have solved the problem.

From the stack trace (included below) it looks like the failure
originates from the following call :

NUnit.Core.DomainInitializer.CreateInstance(AppDomain
targetDomain)

So I downloaded and compiled the source with VS2008 and made changes
as per the blog entry I mentioned in my first message (http://
blogs.msdn.com/b/shawnfa/archive/2009/06/08/more-implicit-uses-of-cas-
policy-loadfromremotesources.aspx). This just involved modifying line
118 of DomainManager.cs as follows (have included the line beginning
log.Info to make it easy to find) :

log.Info("Creating AppDomain " + domainName);

PermissionSet trustedLoadFromRemoteSourceGrantSet = new
PermissionSet( System.Security.Permissions.PermissionState.Unrestricted );
AppDomain runnerDomain =
AppDomain.CreateDomain(domainName, evidence, setup,
trustedLoadFromRemoteSourceGrantSet, null);

Could this change be incorporated into the source for future NUnit
releases ?

I tried to run all the tests to make sure that the change didn't break
anything by running the "NUnitTests.nunit" project (in the vs2008
folder) and found that 2800 tests passed but there were 12 errors.
However, these errors appear to be present in the original
distribution of the source (NUnit-2.5.7.10213-src.zip) i.e. without
any source modifications these 12 errors occur. Also I was unable to
build under the Release configuration in Visual Studio (got a number
of compilation errors). Once I added the conditional compilation
symbol NUNIT_2_5 to the Release configuration of the projects : pnunit-
agent, pnunit-launcher and pnunit.framework it compiled fine.

If you can make this modification and run all the unit tests that
would be great.

Thanks again,
Joel.

Server stack trace:
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName,
String codeBase, Evidence assemblySecurity, RuntimeAssembly
locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound,
Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName,
String codeBase, Evidence assemblySecurity, RuntimeAssembly
locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound,
Boolean forIntrospection, Boolean suppressSecurityChecks)
at
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName
assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark,
Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String
assemblyFile, Evidence securityEvidence, Byte[] hashValue,
AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean
suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile,
Evidence securityEvidence)
at System.Activator.CreateInstanceFromInternal(String assemblyFile,
String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder
binder, Object[] args, CultureInfo culture, Object[]
activationAttributes, Evidence securityInfo)
at System.Activator.CreateInstanceFrom(String assemblyFile, String
typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder,
Object[] args, CultureInfo culture, Object[] activationAttributes,
Evidence securityInfo)
at System.AppDomain.CreateInstanceFrom(String assemblyFile, String
typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder,
Object[] args, CultureInfo culture, Object[] activationAttributes,
Evidence securityAttributes)
at System.AppDomain.InternalCreateInstanceFromWithNoSecurity(String
assemblyName, String typeName, Boolean ignoreCase, BindingFlags
bindingAttr, Binder binder, Object[] args, CultureInfo culture,
Object[] activationAttributes, Evidence securityAttributes)
at System.AppDomain.InternalCreateInstanceFromWithNoSecurity(String
assemblyName, String typeName, Boolean ignoreCase, BindingFlags
bindingAttr, Binder binder, Object[] args, CultureInfo culture,
Object[] activationAttributes, Evidence securityAttributes)
at System.Activator.CreateInstanceFrom(AppDomain domain, String
assemblyFile, String typeName, Boolean ignoreCase, BindingFlags
bindingAttr, Binder binder, Object[] args, CultureInfo culture,
Object[] activationAttributes, Evidence securityAttributes)
at NUnit.Core.DomainInitializer.CreateInstance(AppDomain
targetDomain)
at NUnit.Util.DomainManager.CreateDomain(TestPackage package)
at NUnit.Util.TestDomain.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Util.RemoteTestAgent.AgentRunner.Load(TestPackage package)
at
System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr
md, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInContext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage
msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]:
at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at NUnit.Core.TestRunner.Load(TestPackage package)
at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
at NUnit.Util.ProcessRunner.Load(TestPackage package)
at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options)
at NUnit.ConsoleRunner.Runner.Main(String[] args)
> > loadFromRemoteSources switch. Seehttp://go.microsoft.com/fwlink/?LinkId=155569
> > for more information.
>
> > For some reason the assembly 'nunit.core.DLL' will not load from the
> > networked drive?
>
> > With .Net 2 we needed to use caspol.exe to enable full trust on our
> > networked (J:) drive in order to use assemblies on this drive.
>
> > After reading the link in the error message and also this article :
>
> >  http://blogs.msdn.com/b/shawnfa/archive/2009/06/08/more-implicit-uses...
>
> > I tried enabling the loadFromRemoteSources switch but this did not
> > work (see Note 1 below).
>
> > Notes :
> > 1. I have modified the nunit-console.exe.config is as follows :
> > <configuration>
> >  <startup>
> >    <requiredruntime version="v4.0.30319"> </requiredruntime>
> >  </startup>
> >  <runtime>
> >    <loadFromRemoteSources enabled="true" />
> >  </runtime>
> > </configuration>
>
> > 2. If the nunit-console.exe is on a local drive then it runs fine.
>
> > 3. If the unit test assemblies are built targetting .Net 2 then the
> > tests run fine.
>
> > Any ideas would be much appreciated.
>
> > Thanks in advance,
> > Joel Gordon.
>
> > --
> > You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
> > To post to this group, send email to nunit-...@googlegroups.com.
> > To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/nunit-discuss?hl=en.- Hide quoted text -
>
> - Show quoted text -

Charlie Poole

unread,
Sep 27, 2010, 11:46:41 PM9/27/10
to nunit-...@googlegroups.com
Hi Joel,

Thanks for the fix. If you'll file a bug with a pointer to this thread, I'll get
it into the next release.

Charlie

Joel

unread,
Sep 28, 2010, 4:34:22 PM9/28/10
to NUnit-Discuss
Hi Charlie,

Have filed the following bug report (just included a pointer to
this thread rather than duplicate the details) :

https://bugs.launchpad.net/nunitv2/+bug/650598

If you can include it in the next release that would be great.

Thanks,
Joel.

On Sep 28, 4:46 pm, Charlie Poole <nunit...@gmail.com> wrote:
> Hi Joel,
>
> > System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(I­ntPtr
> > md, Object[] args, Object server, Int32 methodPtr, Boolean
> > fExecuteInContext, Object[]& outArgs)
> >   at
> > System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMess­age
> >> > For more options, visit this group athttp://groups.google.com/group/nunit-discuss?hl=en.-Hide quoted text -
>
> >> - Show quoted text -
>
> > --
> > You received this message because you are subscribed to the
>
> ...
>
> read more »- Hide quoted text -

Charlie Poole

unread,
Sep 28, 2010, 4:58:15 PM9/28/10
to nunit-...@googlegroups.com
Hi Joel,

Got it!

I'll also check out the build problems you ran into with VS2008.
Note that you can't build a copy of NUnit identical to what we
distribute with VS2008, since the distribution includes components
built for .NET 1.1 as well as 2.0. However the missing defines
seems to be a problem.

Charlie

Reply all
Reply to author
Forward
0 new messages