Nant failing with bad permissions on build server
Asked Answered
O

5

17

Total newbie question. I am trying to run a Nant script on a build server (very basic script, not doing anything), and it's failing with the error

System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

What should I do to get it running?

Overcast answered 15/9, 2010 at 14:38 Comment(2)
provide a bit more details: what build server are u using?, what is your Nant script doing? possibly paste sample code.Anaclitic
It seems that this question solves the same issue: #8605622 Hope that helps!Shamble
L
16

@TK has the answer here, I believe, though it may not be as simple as whether or not nant is running from a network drive.

I have had a similar issue as @Aidan. It turns out that I had copied the nantcontrib (v .86) assemblies to my build system in such a way that Windows 7 restricted access to the nantcontrib assemblies. To fix this, I first copied the nantcontrib zip file to my build VM, then overwrote the blocked assemblies with the contents of the .zip. Windows 7 saw that the files were coming from the local system (rather than from whatever untrusted source I had copied from originally) and it unblocked the assemblies.

There is probably a more direct means of trusting the assemblies (such as @TK's link), but this worked for me.

If you see this error again, look for two things:

First, Nant (v .91 alpha 2) does a decent job reporting exactly what the error is. I saw the same error as @Adian, along with a complete error stack, and finally this information (emphasis mine):

The assembly or AppDomain that failed was: NAnt.Contrib.Tasks, Version=0.86.3319.0, Culture=neutral, PublicKeyToken=null The method that caused the failure was: NAnt.Core.Task CreateChildTask(System.Xml.XmlNode)
The Zone of the assembly that failed was: Internet
The Url of the assembly that failed was: file:///C:/Program Files (x86)/NAntBuilder 2/nantcontrib/bin/NAnt.Contrib.Tasks.dll

Second, look at the property page of the offending assembly (in my case, Nant.Contrib.Tasks.dll). If the file has been copied from an untrusted source, you will see an "Unblock" button in the properties section (beneath Advanced...) along with a note which stated that the files had come from an untrusted source.

Londonderry answered 8/9, 2011 at 18:50 Comment(0)
B
28

My error message mentioned the "Internet Zone". This is probably because I downloaded zipped binaries from SourceForge. I zipped and then unzipped to strip the zone and that worked great for me.

On Windows 7 (or similar):

  1. Select all files in the NAnt folder
  2. Right click, Send to > Compressed (zipped) folder
  3. Right click on new zip file and choose "Extract All..."
  4. Extract to a new folder

The extracted files will no longer be from the "Internet Zone". You can copy back into the original directory if you wish.

Bernita answered 27/1, 2012 at 3:55 Comment(1)
This was my exact problem! Thank you!Damalis
L
16

@TK has the answer here, I believe, though it may not be as simple as whether or not nant is running from a network drive.

I have had a similar issue as @Aidan. It turns out that I had copied the nantcontrib (v .86) assemblies to my build system in such a way that Windows 7 restricted access to the nantcontrib assemblies. To fix this, I first copied the nantcontrib zip file to my build VM, then overwrote the blocked assemblies with the contents of the .zip. Windows 7 saw that the files were coming from the local system (rather than from whatever untrusted source I had copied from originally) and it unblocked the assemblies.

There is probably a more direct means of trusting the assemblies (such as @TK's link), but this worked for me.

If you see this error again, look for two things:

First, Nant (v .91 alpha 2) does a decent job reporting exactly what the error is. I saw the same error as @Adian, along with a complete error stack, and finally this information (emphasis mine):

The assembly or AppDomain that failed was: NAnt.Contrib.Tasks, Version=0.86.3319.0, Culture=neutral, PublicKeyToken=null The method that caused the failure was: NAnt.Core.Task CreateChildTask(System.Xml.XmlNode)
The Zone of the assembly that failed was: Internet
The Url of the assembly that failed was: file:///C:/Program Files (x86)/NAntBuilder 2/nantcontrib/bin/NAnt.Contrib.Tasks.dll

Second, look at the property page of the offending assembly (in my case, Nant.Contrib.Tasks.dll). If the file has been copied from an untrusted source, you will see an "Unblock" button in the properties section (beneath Advanced...) along with a note which stated that the files had come from an untrusted source.

Londonderry answered 8/9, 2011 at 18:50 Comment(0)
P
7

This problem is caused by Windows setting the files' "Zone.Identifier" metadata in NTFS to "Internet" (or to another zone which you have to explicitly unblock to gain access).

To not cause file security metadata to be written when you copy files or, in my case, unzip from a zip file on a network drive, either copy the zip file to a local folder before unzipping it, as previously suggested, or run the "streams.exe" tool from Sysinternals to remove that metadata.

For example, if I run streams.exe on exe's in my Downloads folder:

streams.exe *.exe

Streams v1.56 - Enumerate alternate NTFS data streams
Copyright (C) 1999-2007 Mark Russinovich
Sysinternals - www.sysinternals.com

C:\Downloads\jre-6u27-windows-x64.exe:
   :Zone.Identifier:$DATA       26

Normally, streams.exe wouldn't display any metadata information if the files all originated from a local folder. If you do see these ":Zone.Identifier:$DATA" metadata (stored in NTFS as an alternate data stream), then you should also see an Unblock button in the files' Properties dialog.

To unblock the files in bulk, run "streams.exe -s -d *.*" from your problematic folder.

Poplin answered 25/10, 2012 at 17:39 Comment(1)
I did this in the NAnt directory to no avail, then did it in the NH source directory and things started building.Fortna
O
2

When you download NAnt, you have to right click on the zip file (before extracting evertything), then properties, and click on unblock file. Then extract everything and it will work.

Oddment answered 6/11, 2017 at 16:12 Comment(0)
K
0

Are you running the Nant script on a network share drive?

If so then you might need to configure the .NET Caspol policy to allow .NET code to be executed on a network share.

Using CasPol to Fully Trust a Share

This link might be able to help you.

Ketchup answered 4/10, 2010 at 10:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.