Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / November 2006

Tip: Looking for answers? Try searching our database.

FileIOPermission problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Schemer - 20 Nov 2006 14:29 GMT
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...
Jeffrey Tan[MSFT] - 21 Nov 2006 04:08 GMT
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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Willy Denoyette [MVP] - 21 Nov 2006 10:27 GMT
> Hello,
>
[quoted text clipped - 18 lines]
>
> Thanks for any insight...

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

Willy.
Schemer - 27 Nov 2006 13:29 GMT
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@nospam.n
> I am working on a C# console app.
> When I do this:
[quoted text clipped - 12 lines]
>
> but the error still occurs.
Jeffrey Tan[MSFT] - 28 Nov 2006 07:27 GMT
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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.