Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Cannot save a file in my app

Discussion in 'VR' started by LR-Developer, Jun 8, 2017.

  1. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    109
    Hello,

    until now I was using the Binaryformatter but that did not work with Unity UWP so I switched to XML.

    I have a List with a struct in it and want to save it to a file to load it next App start on my hololens.
    I do not care where the file is, just want to save and load it.

    The saving does not seem to work on the hololens (release build).
    I tried LocalFolder and RoamingFolder, both do not work.

    Where or how can I save my List?

    Thanks a lot for your help!

    Code:

    Code (CSharp):
    1.     public static void SaveQRList(string nameList)
    2.     {
    3.         try
    4.         {
    5. #if WINDOWS_UWP
    6.             //StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
    7.             StorageFolder storageFolder = ApplicationData.Current.RoamingFolder;
    8.             nameList = storageFolder + "\\" + nameList;
    9. #endif
    10.             //Speichern
    11.             Stream stream = File.Open(nameList, FileMode.Create);
    12.             //BinaryFormatter writer = new BinaryFormatter();
    13.             XmlSerializer writer = new XmlSerializer(QRCodesList.GetType());
    14.             Debug.Log("Writing Containers");
    15.             writer.Serialize(stream, QRCodesList);
    16.             //stream.Close();
    17.             Debug.Log("Write CodeList finished");
    18.         }
    19.         catch (System.Exception ex)
    20.         {
    21.             Debug.LogError("Save CodeList List Error: " + ex.ToString());
    22.         }
    23.     }
    Error when saving:

    'LR Worlds.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LRWorldsVS.Release_x86.beh\System.Xml.XmlSerializer.dll'. Cannot find or open the PDB file.
    'LR Worlds.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LRWorldsVS.Release_x86.beh\System.Resources.ResourceManager.dll'. Module was built without symbols.
    Exception thrown: 'System.IO.DirectoryNotFoundException' in System.IO.FileSystem.dll
    Save CodeList List Error: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\LRWorldsVS.Release_x86.beh\Windows.Storage.StorageFolder\QRCodesList.ser'.
    at System.IO.Win32FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs)
    at System.IO.Win32FileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
    at System.IO.MultiplexingWin32WinRTFileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
    at Globals.SaveQRList(String nameList)
     
  2. LR-Developer

    LR-Developer

    Joined:
    May 5, 2017
    Posts:
    109
    I found a path that works:

    nameList = Application.persistentDataPath + "\\" + nameList;

    Thanks! Solved.
     
    Last edited: Jun 8, 2017
    longarms07 likes this.