Hello
I have a problem with reading xml writing to load the highest score.
I’m working on: an Android project on Visual Studio mac
I found a piece of code that allows you to load the xml from the 3.8 monogamous Content in Copy mode by associating the DLL
string _fileName= new StreamReader(TitleContainer.OpenStream(@“Content/File.xml”)).ReadToEnd();
Code
namespace xmlTest
{
public class Score
{
// public string PlayerName { get; set; }
// public int Value { get; set; }
public string PlayerName;
public int Value;
}
}
<?xml version="1.0" encoding="utf-8"?> <PlayerName> testPlayer </PlayerName>
<Value> 100 </Value>
I found this code to load and write
using (var reader = new StreamReader(new FileStream(_fileName, FileMode.Open)))
{
var serilizer = new XmlSerializer(typeof(List));
var scores = (List<Score>)serilizer.Deserialize(reader);
return new ScoreManager(scores);
}
using (var writer = new StreamWriter(new FileStream(_fileName, FileMode.Create)))
{
var serilizer = new XmlSerializer(typeof(List<Score>));
serilizer.Serialize(writer, scoreManager.Scores);
}
Error:
System.IO.DirectoryNotFoundException: Could not find a part of the path "/<?xml version="1.0" encoding="utf-8"?>
<PlayerName> testPlayer </PlayerName>
<Value> 100 </Value>
".
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x00177] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/FileStream.cs:223
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/FileStream.cs:81
at at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode)
at xmlTest.Managers.ScoreManager.Load () [0x00001] in /Users/saadaneguessoum/Documents/Projets_monoGame/xmlTest/xmlTest/Managers/ScoreManager.cs:58
at xmlTest.Game1.LoadContent () [0x00028] in /Users/saadaneguessoum/Documents/Projets_monoGame/xmlTest/xmlTest/Game1.cs:57
at Microsoft.Xna.Framework.Game.Initialize () [0x00047] in :0
at xmlTest.Game1.Initialize () [0x00001] in /Users/saadaneguessoum/Documents/Projets_monoGame/xmlTest/xmlTest/Game1.cs:46
at Microsoft.Xna.Framework.Game.DoInitialize () [0x0002c] in :0
at Microsoft.Xna.Framework.AndroidGamePlatform.BeforeUpdate (Microsoft.Xna.Framework.GameTime gameTime) [0x0000e] in :0
at Microsoft.Xna.Framework.Game.DoUpdate (Microsoft.Xna.Framework.GameTime gameTime) [0x00006] in :0
at Microsoft.Xna.Framework.Game.Tick () [0x00131] in :0
at Microsoft.Xna.Framework.AndroidGameWindow.OnUpdateFrame (System.Object sender, Microsoft.Xna.Framework.MonoGameAndroidGameView+FrameEventArgs frameEventArgs) [0x00041] in :0
at Microsoft.Xna.Framework.MonoGameAndroidGameView.UpdateFrameInternal (Microsoft.Xna.Framework.MonoGameAndroidGameView+FrameEventArgs e) [0x0000f] in :0
at Microsoft.Xna.Framework.MonoGameAndroidGameView.UpdateAndRenderFrame () [0x00056] in :0
at Microsoft.Xna.Framework.MonoGameAndroidGameView.processStateRunning (System.Threading.CancellationToken token) [0x0005b] in :0
at Microsoft.Xna.Framework.MonoGameAndroidGameView.RunIteration (System.Threading.CancellationToken token) [0x000f9] in :0
at Microsoft.Xna.Framework.MonoGameAndroidGameView+<>c__DisplayClass62_0.b__0 (System.Object s) [0x00017] in :0
at Android.App.SyncContext+<>c__DisplayClass3_0.b__0 () [0x00000] in <55654ebe9f2a48e6bade2862bb243f94>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <55654ebe9f2a48e6bade2862bb243f94>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <55654ebe9f2a48e6bade2862bb243f94>:0
at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.17(intptr,intptr)
Note: I did not find any problem with the desktop project it loads well and it saves the score
Otherwise if you have another method with Android I am a buyer
thanks in advance