1

I am trying to define a local path for my WPF application to store some JSON files that are generated on operation.

I define a static path like so:

public static string LOCAL_PATH = 
    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

When I run it, I get the following error:

Exception thrown: 'System.Security.SecurityException' in mscorlib.dll
Additional information: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Is there a way to set the permission level of my app higher so that I can access this path?

Other alteranatives are welcome too. I have already gotten the app to work with IsolatedStorage, however that solution is not great because I would like the files to be in an accessible location for the user to modify outside of my app if needed.

Thanks!

Pol
  • 306
  • 2
  • 12
  • the one I posted above, where I define the local path variable – Pol Mar 07 '16 at 19:55
  • 2
    Please show us the complete code block. I've just placed it in MainWindow() constructor and tested (string LOCAL_PATH = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);) - it works just fine. Best regards, – Alexander Bell Mar 07 '16 at 20:01
  • 1
    I have found that for debugging it is easier to just define a conditional compilation symbol: define #DEBUG and then #if (DEBUG == TRUE) { doc.Save(Environment.CurrentDirectory + "/doc.json") } #endif – aguertin Mar 07 '16 at 20:03
  • 1
    Run temporarily you application as administrator and see what folder it returns, maybe the special folder is pointing to an odd place or your permissions are messed up. – Frank J Mar 07 '16 at 20:03
  • I ended up fixing the issue by deleting my manifest and creating a new one. So the code works as is. Thank to all! – Pol Mar 07 '16 at 20:48

1 Answers1

1

I finally fixed it by deleting the app.manifest and creating it again. For some reason, the file might have become corrupted.

Hope this helps someone else with a similar issue.

Pol
  • 306
  • 2
  • 12