The Mixed Reality Forums here are no longer being used or maintained.
There are a few other places we would like to direct you to for support, both from Microsoft and from the community.
The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.
For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.
If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.
And always feel free to hit us up on Twitter @MxdRealityDev.
Save and Load app data with XML file error -
Hi, I am trying to save and load scene data using XML. Following this tutorial, I was able to save and load in the Unity editor (game mode).
https://youtu.be/Y8Di-Q6qpU4
However, in device or emulator, I am getting this error:
UnauthorizedAccessException: Access to the path .......\Data\Resources\actors.xml' is denied.
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 SaveData.SaveActors(String path, ActorContainer actors)
at SaveData.Save(String path, ActorContainer actors)
at HoloToolkit.Unity.ButtonEvent.OnSelect()
at HoloToolkit.Unity.ButtonEvent.$Invoke5OnSelect(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
Here is the code that saves and loads XML file. According to initial investigation, it looks like it is related to UWP's access limitation to the local files/folders. The xml file is under Data/Resources/ folder. Any suggestions would be appreciated! Thanks!
private static ActorContainer LoadActors(string path) { XmlSerializer serializer = new XmlSerializer(typeof(ActorContainer)); FileStream stream = new FileStream(path, FileMode.Open); ActorContainer actors = serializer.Deserialize(stream) as ActorContainer; stream.Dispose(); return actors; } private static void SaveActors(string path, ActorContainer actors) { XmlSerializer serializer = new XmlSerializer(typeof(ActorContainer)); FileStream stream = new FileStream(path, FileMode.Truncate); serializer.Serialize(stream, actors); stream.Dispose(); }
Best Answer
-
OptionsHoloSheep mod
Not sure, but at first glance I think your issue is that you have code after your
task.Wait();
that depends on the results of nested await calls.
Have you tried slapping a break statement on every line of code in say your LoadActors routine and stepping through it one line at a time and watching the order that they get executed in? I think you might find that the lines after the task.Wait() calls are getting run before the inner
stream = await file.OpenStreamFor...
lines are returning.
The task.wait is not waiting for the inner asynchronous calls to complete.
That would be my guess.HTH.
Windows Holographic User Group Redmond
WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
WinHUGR YouTube Channel -- live streamed meetings6
Answers
@cre8ivepark
Here is a sample of saving and reading files with the UWP syntax in Unity in case it helps.
Windows Holographic User Group Redmond
WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
WinHUGR YouTube Channel -- live streamed meetings
@HoloSheep Thank you so much!
I found similar code in HoloToolkit's MeshSaver.cs and replaced FileStream related code with your suggestion. Now both saving and loading are working when I try for the first time but it gives me these errors (both for saving and loading). It only works first time when I close the app and fresh start. Then it generates these errors. I have no clue... Not sure if it is related to stream.Dispose() or Flush()
Thank you!
******************** Load *********************************
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/UnityEngineDebugBindings.gen.cpp Line: 45)
ArgumentNullException: Value cannot be null.
Parameter name: input
at System.Xml.XmlReaderSettings.CreateReader(Stream input, Uri baseUri, String baseUriString, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(Stream input, XmlReaderSettings settings, String baseUri)
at System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)
at SaveData.LoadActors(String path)
at SaveData.Load(String path)
at HoloToolkit.Unity.ButtonEvent.OnSelect()
at HoloToolkit.Unity.ButtonEvent.$Invoke5OnSelect(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
(Filename: Line: 0)
******************** Save *********************************
ArgumentNullException: Value cannot be null.
Parameter name: output
at System.Xml.XmlWriterSettings.CreateWriter(Stream output)
at System.Xml.XmlWriter.Create(Stream output, XmlWriterSettings settings)
at System.Xml.Serialization.XmlSerializer.Serialize(Stream stream, Object o, XmlSerializerNamespaces namespaces)
at SaveData.SaveActors(String path, ActorContainer actors)
at SaveData.Save(String path, ActorContainer actors)
at HoloToolkit.Unity.ButtonEvent.OnSelect()
at HoloToolkit.Unity.ButtonEvent.$Invoke5(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
(Filename: Line: 0)
Code ------------------------------------------------------------
http://typeinsight.org/hololens
@cre8ivepark
Not sure, but at first glance I think your issue is that you have code after your
task.Wait();
that depends on the results of nested await calls.
Have you tried slapping a break statement on every line of code in say your LoadActors routine and stepping through it one line at a time and watching the order that they get executed in? I think you might find that the lines after the task.Wait() calls are getting run before the inner
lines are returning.
The task.wait is not waiting for the inner asynchronous calls to complete.
That would be my guess.
HTH.
Windows Holographic User Group Redmond
WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
WinHUGR YouTube Channel -- live streamed meetings
Thank you very much @HoloSheep I was able to remove those errors but I spent few days with this different error. It looks like it is related to transform but when I check it is not null. I couldn't find this keyword Component_Get_Custom_PropTransform from Unity forum.
NullReferenceException: Exception of type 'System.NullReferenceException' was thrown.
at WinRTBridge.Utils.ThrowNewNullReferenceException(String message)
at UnityEngineProxy.InternalCalls.PInvokeCalls.Component_Get_Custom_PropTransform(IntPtr param_0)
at UnityEngineProxy.InternalCalls.Component_Get_Custom_PropTransform(Object self)
at Actor.StoreData()
at Actor.b__8_1()
at SaveData.SerializeAction.Invoke()
at SaveData.Save(String path, ActorContainer actors)
at HoloToolkit.Unity.ButtonEvent.OnSelect()
at HoloToolkit.Unity.ButtonEvent.$Invoke5OnSelect(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
Related code is:
This script is included in the GameObject, which is instantiated from a prefab resource. Not sure how transform could be null.
http://typeinsight.org/hololens
Resolved the issue and now XML save and load is working. Thank you @HoloSheep for your suggestion!
http://typeinsight.org/hololens