Sign in to follow this  

[.net] FileIOPermission & ApplicationData

This topic is 3295 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

On some computers my application is throwing an exception when trying to create a folder in:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
And the exeption is:
Request for the permission of type 'System.Security.Permissions.FileIOPermission' failed.
I believe that there is some sort of antivirus running on their machines but I haven't been able to get in contact with their IT to find out what exactly they are running. Is there a standard way to handle permissions for antivirus software? Any idea what steps I should take to get around this?

Share this post


Link to post
Share on other sites
Are you sure it's not Vista's UAC? If so you can right click your program's shortcut and select to "Run as admininistrator" from advanced properties, or right click the exe and select "Run this program as administrator" in the "Privilege Level" setting under the Compatability tab in the exe's Properties. Or set it in the registry directly in the following key.

Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers


Create a string key with the name as your exe's full path and a value of "RUNASADMIN".

Share this post


Link to post
Share on other sites
Quote:
Original post by Headkaze
Are you sure it's not Vista's UAC?


It couldn't be UAC since the ApplicationData folder is inside the user's profile.

The FileIOPermission doesn't actually have anything to do with filesystem security anyway - it's a CAS thing. Most likely, the people running into this problem are running your program from a network share and so the application isn't running with FullTrust.

Or possibly, their IT department is using the CASpol tool to lock down the security of the applications they're running.

Do you absolutely 100% have to create folders in ApplicationData? Can you use isolated storage instead? Isolated storage plays better with non-FullTrust applications.

Share this post


Link to post
Share on other sites
It's definitely not UAC since the problem is occuring under XP and not Vista. I'll check to verify that the user has the app installed on a network drive, but I'll bet that's the problem. I'll look into isolated storage, thanks for the link!

Share this post


Link to post
Share on other sites
Isolated Storage has the exact same problem, and it is caused by running from a network share as opposed to running locally. The solution appears to be granting full trust permissions to the application.

Quote:
How to deploy a .NET Framework application to run from a network location
Assign Full Trust permission
Do the following, depending on your operating system:
On Windows XP, click Start, and then click Control Panel.
On Windows 2000, click Start, point to Settings, and then click Control Panel.
Do the following, depending on the version of the .NET Framework that you are using:
If you are using the .NET Framework 1.1, double-click Administrative Tools, and then double-click Microsoft .NET Framework 1.1 Wizards.
If you are using the .NET Framework 1.0, double-click Administrative Tools, and then double-click Microsoft .NET Framework Wizards.
The .NET Wizards window appears.
In the .NET Wizards window, click Trust an Assembly. The Trust an Assembly dialog box appears.
Click to select the Make changes to this computer option, and then click Next.
Click Browse. The Choose Assembly dialog box appears.
In the Choose Assembly dialog box, locate the executable file on the mapped network drive, and then click Open.
In the Trust an Assembly dialog box, click Next.
In the Trust an Assembly dialog box, move the slider to Full Trust, and then click Next.
Click Finish.
To run the executable file from the mapped network drive, double-click the file in Windows Explorer.

Share this post


Link to post
Share on other sites
Quote:
Original post by tstrimp
Isolated Storage has the exact same problem, and it is caused by running from a network share as opposed to running locally. The solution appears to be granting full trust permissions to the application.


Isolated Storage should work with partial trust. This article is a bit old, but still provides some useful information. There are plenty of other things which could be causing those SecurityExceptions if you're running from a network share.

As you say, though, if granting FullTrust to the application is an option, then the solution is pretty easy :-)

Share this post


Link to post
Share on other sites
Quote:
Original post by Codeka
As you say, though, if granting FullTrust to the application is an option, then the solution is pretty easy :-)


Except the .net wizard for configuring the full trust only comes with the .net SDK, not the redist that the clients will most likely have. Ah well. I'm to the point of saying we don't support installation to network shares.

Share this post


Link to post
Share on other sites
I think .Net 3.5 SP1 increased the default permissions of programs running from network shares. I don't know if this is feasible for your purposes, but you could add a requirement of 3.5 SP1 when running from network shares.

Share this post


Link to post
Share on other sites

This topic is 3295 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this