HighTechTalks DotNet Forums  

FileIOPermission problem

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss FileIOPermission problem in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Schemer
 
Posts: n/a

Default FileIOPermission problem - 11-20-2006 , 09:29 AM






Hello,

I am working on a C# console app.
When I do this:

DirectoryInfo di = new DirectoryInfo(".");

I get an exception:
Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

I added this before the DirectoryInfo creation:

FileIOPermission f = new FileIOPermission(PermissionState.None);
f.AllLocalFiles = FileIOPermissionAccess.Read;

but the error still occurs.

My app needs to read certain files in the current dir, and then create new
files. How does the app get the permissions to do those things?

Thanks for any insight...



Reply With Quote
  #2  
Old   
Jeffrey Tan[MSFT]
 
Posts: n/a

Default RE: FileIOPermission problem - 11-20-2006 , 11:08 PM






Hi Schemer,

Can you provide the full stack trace of this exception? This will reveal
much important information of the failure.

Based on the error message, this exception is most likely of type
SecurityException, which is thrown by .Net Code Access Security engine. The
Net SecurityException is most likely caused by running the application
from a partial trusted location, because CLR will give limited permission
to partial trusted location running application. So, can you provide more
context information of your problem and application? For example, where do
you launch the application, local folder or network share?

It is strange that your application throws SecurityException while
constructing DirectoryInfo for current folder ".", because I have created a
little sample project which calls DirectoryInfo di = new
DirectoryInfo("."). Then I placed this test assembly in a network share
folder and no SecurityException will generate in the test. So, I recommend
you provide more detailed information to help me reproduce the problem.
This will be more efficient to reduce the troubleshooting time. Thanks.

Finally, setting FileIOPermission.AllLocalFiles property to
FileIOPermissionAccess.Read does not mean that it will give file read I/O
permission to all local files. But, it means that you want to check your
application's file read I/O permission to all local files. To explicitly
test this, you should use FileIOPermission.Demand method to force the .Net
runtime security checking. Actually, if this property can be used to grant
FileIOPermission to an application, this will become a big security hole,
because any untrusted application can use this property to acquire
FileIOPermission, which workarounds the .Net CAS engine.

Additionally, there is an easy to understand .Net CAS article in
codeproject, it will provide more useful .Net CAS background information to
you:
"Understanding .NET Code Access Security"
http://www.codeproject.com/dotnet/UB_CAS_NET.asp

I look forward to your further information. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
  #3  
Old   
Willy Denoyette [MVP]
 
Posts: n/a

Default Re: FileIOPermission problem - 11-21-2006 , 05:27 AM



"Schemer" <jumper (AT) nospam (DOT) nospam> wrote

Quote:
Hello,

I am working on a C# console app.
When I do this:

DirectoryInfo di = new DirectoryInfo(".");

I get an exception:
Request for the permission of type 'System.Security.Permissions.FileIOPermission,
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

I added this before the DirectoryInfo creation:

FileIOPermission f = new FileIOPermission(PermissionState.None);
f.AllLocalFiles = FileIOPermissionAccess.Read;

but the error still occurs.

My app needs to read certain files in the current dir, and then create new files. How
does the app get the permissions to do those things?

Thanks for any insight...


Do you happen to run this application from a network share?

Willy.





Reply With Quote
  #4  
Old   
Schemer
 
Posts: n/a

Default Re: FileIOPermission problem - 11-27-2006 , 08:29 AM



Thanks for the replies.

Unfortunately, I have been unable to reproduce the problem since re-starting
the computer.
I removed references to FileIOPermission. Instead, I create my input
FileStream as
new FileStream(fn, FileMode.Open, FileAccess.Read, FileShare.Read);
and my output stream as either
fsOut = File.Open(fnOut, FileMode.Append);
or
fsOut = File.Open(fnOut, FileMode.Create);

Does the Security tab in the project's options have anything to do with
runtime issues, or just deployment?

Thanks again for the help.


"Schemer" <jumper (AT) nospam (DOT) n
Quote:
I am working on a C# console app.
When I do this:

DirectoryInfo di = new DirectoryInfo(".");

I get an exception:
Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

I added this before the DirectoryInfo creation:

FileIOPermission f = new FileIOPermission(PermissionState.None);
f.AllLocalFiles = FileIOPermissionAccess.Read;

but the error still occurs.




Reply With Quote
  #5  
Old   
Jeffrey Tan[MSFT]
 
Posts: n/a

Default Re: FileIOPermission problem - 11-28-2006 , 02:27 AM



Hi Schemer,

Thanks for your feedback!

What is the setting in "Security" tab of your project? This "Security" tab
is used for debugging ClickOnce application. It can also be used to launch
the application under a limited permission set to simulate the partial
trusted location. However, normally, we will not check "Enable ClickOnce
Security Setttings" checkbox. Do you check it in your project which caused
the CAS exception?

I will wait for your further information. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.