IntermediateSerializer.Serialize not work

Good day! Help solve the problem… Wanted to hold a serialization of a
very simple class method of the

            using (XmlWriter writer = XmlWriter.Create("test.xml", settings))
            {
                IntermediateSerializer.Serialize<string>(writer, "test", null);
            }

, but the result is zero (xml file is empty). Reading other forums, I stumbled on a post
that supposedly it is necessary to replace Monogame.Content.Pipeline.dll
on the project with Github and point to it a link in your project -
checked, did not help. Maybe this method doesn’t work anymore? Help,
please. My configuration: VS2017, MonoGame 3.7.1, XNA installed in
parallel. P.S. perhaps, you not understood my words, for I’m using Google Translater, tnx.

You have to call Close(); before it will write anything.

Probably easier ways to serialize a class. The writer itself works fine though.

output in file.

<?xml version="1.0" encoding="utf-8"?><cat:speak xmlns:cat="meow" />

// using directive
using System.Xml;

        protected override void LoadContent()
        {
            Cat cat = new Cat();
            XmlWriter xmlWriter = XmlWriter.Create(MgPathFolderFileOps.CombinePath(MgPathFolderFileOps.ApplicationPath, "cat.xml"));
            xmlWriter.WriteStartElement("cat", "speak", cat.speak.ToString() );
            xmlWriter.Close();

        }

    // below Game1  {}
    public class Cat
    {
        public string speak = "meow";
    }

xml writer is not the xml serializer which is much easier to use.

xml serializer

https://docs.microsoft.com/en-us/dotnet/standard/serialization/how-to-serialize-an-object

https://docs.microsoft.com/en-us/dotnet/standard/serialization/how-to-deserialize-an-object

using System.Xml.Serialization;

var cat = new Cat();

XmlSerializer xs = new XmlSerializer(typeof(Cat));
TextWriter tw = new StreamWriter(@"c:\temp\cat.xml");
xs.Serialize(tw, cat);

// load cat from file:

using(var sr = new StreamReader(@"c:\temp\cat.xml"))
{
   cat= (Cat)xs.Deserialize(sr);
}

Correct! I did not make the completion of the XmlWriter. Thank You!

finaly it works for me too :slight_smile: thank you