When saving on WP8 (Nokia 520, Unity 4.5.3f3), I get the following exception:
A first chance exception of type ‘System.Exception’ occurred in WinRTLegacy.DLL
Exception: Unsupported uri: c:/data/users/defapps/appdata/{c133a4f8-83a8-4125-a749-a6480c9068c2}/local\autosave.litdsavedgame
at WinRTLegacy.UnityFileStreams.OpenFile(String uri, FileMode mode)
at WinRTLegacy.UnityFileStreams.OpenFileForWriting(String uri)
at System.Xml.XmlTextWriter…ctor(String filename, Encoding encoding)
at System.Xml.XmlDocument.Save(String filename)
The file path is generated as follows:
var path = System.IO.Path.Combine(Application.persistentDataPath, filename);
…
var doc = new XmlDocument();
…
doc.Save(path);
I tried changing the "" in the file path to “/” - same result. Anyone have any ideas? This code works fine on Windows / Android / iOS.
Hi, this might be a bug in our XML implementation. Could you try changing all ‘/’ path separators to '' ones? If that doesn’t work, could you try replacing Application.persistentDataPath with “ms-appdata:///local/”?
The present implementation of XML classes on Windows Phone/Windows Store Apps only supports URIs, not paths.
This will be improved in 5.0.
For now use isostore:/ on WP and ms-appdata:/// uris.
Replacing ‘/’ with '' didn’t work. I am trying to use the alternate path prefixes but no success so far. I don’t get the “unsupported uri” exception any more but the game acts like no data has been saved. Just to be 100% clear: Should I be replacing:
var path = System.IO.Path.Combine(Application.persistentDataPath, filename);
So… I tried but was not able to get a save game saving using the isostore:/ uri (no errors but the code acted like the save game wasn’t there - quite possibly I was doing something wrong). I ended up adding some ifdef’d code that followed the example outlined here on how to access isolated storage with xml: How to: Save to and Load from Isolated Storage with LINQ to XML | Microsoft Learn. That worked for me!
I’m targetting WP8.1. Did the change you said. File path is “isostore:///local/GameData.dat”, and got error.
An exception of type 'System.IO.IsolatedStorage.IsolatedStorageException' occurred in mscorlib.ni.dll but was not handled in user code
Additional information: Operation not permitted on IsolatedStorageFileStream.
I can’t seem to be able to use that for some reason. Does it need any compiler arguments? Also in the documentation it says “This is an alternative for System.IO.File class.” so they must be alike.
What do you mean Tomas? I just have to add the using inside the cs file and I get this error in Unity Editor:
Assets/Scripts/blabla.cs(9,19): error CS0234: The type or namespace name `Windows' does not exist in the namespace `UnityEngine'. Are you missing an assembly reference?