FileIO Exception and permissions

J

jporter188

Hello,

I am working on a project to manipulate XML files. All of the files,
the code, and the output are on network drives. When I run my program
I get an exception (see below). I tried giving the LocalIntranet_Zone
full permissions in the .NET Framework 2.0 Configuration msc. This had
no effect whatsoever. What do I need to do to fix this?

Thanks,

Jeremy


/************************************************
//Exception

Unhandled Exception: System.Security.SecurityException: Request for
the permissi
on of type 'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.
0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand,
StackCrawlMa
rk& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.DirectoryInfo..ctor(String path)
at TEILibrary.getFiles(String strFolderPath)
at TEIConsole.Program.Main(String[] args)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
The first permission that failed was:
<IPermission class="System.Security.Permissions.FileIOPermission,
mscorlib, Vers
ion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Read="X:\xml\."/>

The demand was for:
<IPermission class="System.Security.Permissions.FileIOPermission,
mscorlib, Vers
ion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Read="X:\xml\."/>

The granted set of the failing assembly was:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Permissions.FileDialogPermission,
mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Access="Open"/>
<IPermission
class="System.Security.Permissions.IsolatedStorageFilePermission, m
scorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089"
version="1"
Allowed="ApplicationIsolationByUser"
UserQuota="512000"/>
<IPermission class="System.Security.Permissions.SecurityPermission,
mscorlib, Ve
rsion=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="Execution"/>
<IPermission class="System.Security.Permissions.UIPermission,
mscorlib, Version=
2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Window="SafeTopLevelWindows"
Clipboard="OwnClipboard"/>
<IPermission class="System.Security.Permissions.UrlIdentityPermission,
mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Url="file:///X:/dev/TEIConsole/TEIConsole/bin/Release/TEIConsole.exe"/<IPermission
class="System.Security.Permissions.ZoneIdentityPermission, mscorlib
, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Zone="Trusted"/>
<IPermission class="System.Drawing.Printing.PrintingPermission,
System.Drawing,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
version="1"
Level="SafePrinting"/>
<IPermission class="System.Security.Permissions.MediaPermission,
WindowsBase, Ve
rsion=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
version="1"
Audio="SafeAudio"
Video="SafeVideo"
Image="SafeImage"/>
<IPermission class="System.Security.Permissions.WebBrowserPermission,
WindowsBas
e, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
version="1"
Level="Safe"/>
</PermissionSet>

The assembly or AppDomain that failed was:
TEIConsole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
The method that caused the failure was:
System.Collections.ArrayList getFiles(System.String)
The Zone of the assembly that failed was:
Trusted
The Url of the assembly that failed was:
file:///X:/dev/TEIConsole/TEIConsole/bin/Release/TEIConsole.exe
/
***********************************************************************

public ArrayList getFiles(String strFolderPath)
{
//create a directoryinfo object
DirectoryInfo objDirInfo = new DirectoryInfo(strFolderPath);

//get the FileInfo array
FileInfo[] arrFileInfo = objDirInfo.GetFiles();

ArrayList arrFiles = new ArrayList();

for (int i = 0; i < arrFileInfo.Length; i++)
{
arrFiles.Add(arrFileInfo.Name);
//arrFiles = arrFileInfo.Name;
}

return arrFiles;
}

/
**********************************************************************
Microsoft Visual Studio 2005
Version 8.0.50727.762 (SP.050727-7600)
Microsoft .NET Framework
Version 2.0.50727

Installed Edition: C# Express

Microsoft Visual C# 2005 76544-000-0000011-00126
Microsoft Visual C# 2005
 
M

Mr. Arnold

Hello,

I am working on a project to manipulate XML files. All of the files,
the code, and the output are on network drives. When I run my program
I get an exception (see below). I tried giving the LocalIntranet_Zone
full permissions in the .NET Framework 2.0 Configuration msc. This had
no effect whatsoever. What do I need to do to fix this?

The XML files need to be on an accessible Network Share. It seems to me that
you simply have a permission issue with the User Account being ran on the
machine, which the program running under those User Account permissions will
have as permission rights. If this is a Web based solution, then the ASPNET
machine account may be coming into play as well.
 
J

jporter188

The XML files need to be on an accessible Network Share. It seems to me that
you simply have a permission issue with the User Account being ran on the
machine, which the program running under those User Account permissions will
have as permission rights. If this is a Web based solution, then the ASPNET
machine account may be coming into play as well.

I am running this as a console application under my domain user
account. The domain user account has Modify, Read & Execute, List
Folder Contents, Read, Write NTFS permissions. Everyone has Full
Control on share permissions. I can access all of the XML files for
reading/wrting under any text editor using my domain user account. I
don't think it is a simple file permissions issue in the operating
system--it has to be in .NET. Any ideas?

Thanks!

Jeremy
 
J

jporter188

I am running this as a console application under my domain user
account. The domain user account has Modify, Read & Execute, List
Folder Contents, Read, Write NTFS permissions. Everyone has Full
Control on share permissions. I can access all of the XML files for
reading/wrting under any text editor using my domain user account. I
don't think it is a simple file permissions issue in the operating
system--it has to be in .NET. Any ideas?

Thanks!

Jeremy- Hide quoted text -

- Show quoted text -

I forgot to mention that the program works when I copy and run it on
the local machine.
 
M

Mr. Arnold

I forgot to mention that the program works when I copy and run it on
the local machine.

Your .Net Development machine as opposed to it being ran on a server, as an
example?

I would look at the .Net machine.config file. I know there is a .NET
utility to set application permission on a machine, but I don't remember the
name of the utility.

On your local machine, if that is your development machine, the program has
the .Net permissions, and when it's deployed to another machine it doesn't
have those permissions.

You may also want to look into setting a Domain Group Policy for .Net
applications.
 
J

jporter188

Your .Net Development machine as opposed to it being ran on a server, as an
example?

I would look at the .Net machine.config file. I know there is a .NET
utility to set application permission on a machine, but I don't remember the
name of the utility.

On your local machine, if that is your development machine, the program has
the .Net permissions, and when it's deployed to another machine it doesn't
have those permissions.

You may also want to look into setting a Domain Group Policy for .Net
applications.- Hide quoted text -

- Show quoted text -

Maybe I'm not explain this clearly. The program resides on a network
share and is run from the development machine on a network share. The
program is never run from any other computer. When it is run from the
network share it does not work. When I copy the program to a local
drive it works fine.

What domain policy would I set and what would that do exactly?

What am I looking for in Machine.Config?

Thanks for your help!

Jeremy
 
J

jporter188

Maybe I'm not explain this clearly. The program resides on a network
share and is run from the development machine on a network share. The
program is never run from any other computer. When it is run from the
network share it does not work. When I copy the program to a local
drive it works fine.

What domain policy would I set and what would that do exactly?

What am I looking for in Machine.Config?

Thanks for your help!

Jeremy- Hide quoted text -

- Show quoted text -

Any ideas?
 
R

ryan.casillo

Any ideas?

I think you're getting a security exception because your application
is being run from a network share and the default security policy
for .NET is granting partial trust to your application. When you run
the application on your local drive .NET gives the assembly full
trust. Take a look at Code Access Security.
 
M

Mr. Arnold

Sorry, I had not paid attention to this post. I got too many reply posts in
other NG(s) I can't keep track of them all. :)

Anyway, the fact that it won't work on a network share, which is on a
machine that doesn't have .Net Sercurity coniguration set right as opposed
to you running this application on a loacal machine is an indication of what
is wrong.

The program is trusted on the local machine.

You'll have to talk with your Domain Admin people about setting Domain
policies for any machine connected to a Domain. There can be a policy set
for each machine for .NET that the machine will adhear to. I don't know what
has to be set, just know that it can.

Any ideas?

1) How to use the .Net Framework Configuration Utility for 1.1, 2.0 or 3.0.

2) How to use the SecPol.exe at the Command Prompt.

3) How to use the .Net Framework GacUtil.exe at the Command Prompt.

There should be articles out there on Google covering the 3 above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top