FileIOPermission

  • Thread starter Thread starter Emil
  • Start date Start date
E

Emil

When I compile the application and run it (on my computer) it works fine, by
on the other computers exception is thrown: "Request for the permission of
type 'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

Exception occurs at this: DirectoryInfo currentDir = new
DirectoryInfo("C:\\");

What should I do to allow running this application on other computers than
mine ?
 
When I compile the application and run it (on my computer) it works fine, by
on the other computers exception is thrown: "Request for the permission of
type 'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

Exception occurs at this: DirectoryInfo currentDir = new
DirectoryInfo("C:\\");

What should I do to allow running this application on other computers than
mine ?

Maybe the account the application is running under in the other computers
does not have access to drive c:\
 
Rad said:
Maybe the account the application is running under in the other computers
does not have access to drive c:\


Nope, this not a Windows access rights issue, it's a CAS error message. It means that the
"code" is loaded from a location that has no FileIOPermissions in it's permission-set, that
means it doesn't load from a local drive but from a "network" drive.

Willy.
 
Emil said:
The executable is ON that machine.

On WHAT machine, it's clear that the code is loaded from a *non* local drive, code that
loads from local drives run with full-trust, that means they have full IO access.

Willy.
 
Unless the CAS has been changed on the machines he's trying to run the exe
on so as to not give any code Full Trust (i've never delved into modifying
from the default settings installed).

If you're not the admin of the machines it could be worth asking the admin
if they have modified any of the .NET CAS settings in Control
Panel->Administrative Tools->Microsoft .NET Framework x.x Configuration.

Luke
 
Luke Smith said:
Unless the CAS has been changed on the machines he's trying to run the exe on so as to not
give any code Full Trust (i've never delved into modifying from the default settings
installed).

If you're not the admin of the machines it could be worth asking the admin if they have
modified any of the .NET CAS settings in Control Panel->Administrative Tools->Microsoft
.NET Framework x.x Configuration.

IMO this is very unlikely, first the tool is no longer distributed with the V2.0 framework
(only included with the SDK or VS install), second , IMO the OP is the admin, do you think
he removed FIleIOPermissions from the fulltrust permission set?

Willy.
 
Uzytkownik "Willy Denoyette said:
Nope, this not a Windows access rights issue, it's a CAS error message. It
means that the "code" is loaded from a location that has no
FileIOPermissions in it's permission-set, that means it doesn't load from
a local drive but from a "network" drive.

Willy.


It's loaded from a local drive. I've simply created the application, copied
to usb flash disc, then copied it from usb flash disc to the local drive on
the other computer (with windows Xp installed, and user logged as an
administrator, and where Total Commander works fine with full access to
drive C:\). And when I try to run this application I get this error. It
happens on all computers except mine. I found a solution to add a
certificate or sign the application with some key but it's to complicated
for me.

Emil
 
OK, I've solved the problem.
The security exception really occured at this:
DriveInfo[] Drives = DriveInfo.GetDrives();
foreach (disc in Drives) comboBox1.Items.Add (disc.Name);

I've changed it to:
for (int i=0;i<Directory.GetLogicalDrives().Length;i++)
comboBox1.Items.Add(Directory.GetLogicalDrives());

and now it works fine. Notice that string[] drives =
DriveInfo.GetLogicalDrives(); would also throw Security Exception. Why ? I
don't know ;)

thanks for help anyway
 
Emil said:
OK, I've solved the problem.
The security exception really occured at this:
DriveInfo[] Drives = DriveInfo.GetDrives();
foreach (disc in Drives) comboBox1.Items.Add (disc.Name);

I've changed it to:
for (int i=0;i<Directory.GetLogicalDrives().Length;i++)
comboBox1.Items.Add(Directory.GetLogicalDrives());

and now it works fine. Notice that string[] drives = DriveInfo.GetLogicalDrives(); would
also throw Security Exception. Why ? I don't know ;)



foreach (disc in Drives) ???
doesn't compile! I guess you meant it to be something like:
foreach(DriveInfo disc in Drives)

DriveInfo.GetLogicalDrives(); ??????
Doesn't compile, DriveInfo has no GetLogicalDrives method !
I guess you meant Directory.GetLogicalDrives()

Anyway, DriveInfo needs the "File IO" permission set be granted, Directory does not need
this!. So, once again, this all wouldn't be a problem if your code ran in the "FullTrust"
permission set, which it obviously doesn't.
Willy.
 
Back
Top