Search Unity

[To Delete] Application.persistentDataPath Access denied UWP only

Discussion in 'Windows' started by ben-maurin, Jun 21, 2017.

  1. ben-maurin

    ben-maurin

    Joined:
    Apr 7, 2016
    Posts:
    47
    Hello,

    I try to port a game into UWP for windows 10 but I have some issues that I don't have in normal PC build.
    One of them is that the access to Application.persistentDataPath is denied when doing that File.Create(path).
    I got this error :

    Is there something to launch game with admin access (by doing build and run or when debuging with visual studio) ? some authorization to setup in the project?

    Thank in advance


    EDIT:

    In fact the problem come when trying to create two files in the same directory like this :

    Code (CSharp):
    1.  
    2.             using (FileStream file = File.Create(path1))
    3.             {
    4.                 bf.WriteObject(file, SaveManager.allSavedData);
    5.                 file.Dispose();
    6.             }
    7.  
    8.             using (FileStream file = File.Create(path2))
    9.             {
    10.                 file.Dispose();
    11.             }
    12.  
    Here path1 and path2 are Application.persistentDataPath + separator + a name.
    The error come when creating at path2. In .Net you cannot use stream.Close(), but with using and dispose it should leave the access , right?


    EDIT2 :
    I'm dumb, nevermind.
    The problem was a missing separator and you don't have access to 'C:\Users\AppData\Local\Packages\MyGame' but to 'C:\Users\AppData\Local\Packages\MyGame\LocalState'.
     
    Last edited: Jun 21, 2017
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    By the way, you don't need to call .Dispose manually when using "using {} " block. It does that for you.