Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 602651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:50:43+00:00 2026-05-13T16:50:43+00:00

I am having trouble serializing an object to xml. I have one class that

  • 0

I am having trouble serializing an object to xml.

I have one class that serializs fine:

public class GlobalInfo
{
    public string Ripper = "";
    public string Lineage = "";
}

I have the code that serializes it here (GlobalInfoData is an instance of GlobalInfo class above)

            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(GlobalInfoData.GetType());
            TextWriter w = new StreamWriter(Application.StartupPath + @"\GlobalInfo.xml");
            x.Serialize(w, GlobalInfoData);
            w.Close();

This works fine.

I then have another class:

public class Settings
{
    public delegate void SettingsChangedHandler(object sender, EventArgs e);
    public event SettingsChangedHandler SettingsChanged;

    #region SoX
    private string sox_path;
    public string SOX_PATH { get { return sox_path; } }

    private string sox_version;
    public string SOX_VERSION { get { return sox_version; } }

    public bool SetSOXPath(string soxpath)
    {

        string sox_result = ValidateSOX(soxpath);
        if (sox_result != null)
        {
            sox_path = soxpath;
            sox_version = sox_result;
            return true;
        }
        else
        {
            sox_path = "";
            sox_version = "";
            return false;
        }
    }

    public string ValidateSOX(string soxpath)
    {
        if (Path.GetFileName(soxpath).ToUpper() == "SOX.EXE")
        {
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            proc.StartInfo.CreateNoWindow = true;
            proc.EnableRaisingEvents = false;
            proc.StartInfo.FileName = soxpath;
            proc.StartInfo.Arguments = "--version";
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.UseShellExecute = false;
            proc.Start();

            string output = proc.StandardOutput.ReadToEnd();
            proc.WaitForExit();

            if (output.Contains("sox: SoX v") == true)
            {
                int i = output.IndexOf("sox: SoX v");
                string version = output.Substring(i + 10);
                return version;
            }
            else
            {
                return null;
            }
        }
        else
            return null;
    }
    #endregion

    #region LAME
    private string lame_path;
    public string LAME_PATH { get { return lame_path; } }

    public bool SetLAMEPath(string lamepath)
    {
        if (ValidateLAME(lamepath) == true)
        {
            lame_path = lamepath;
            return true;
        }
        else
        {
            lame_path = "";
            return false;
        }
    }

    public bool ValidateLAME(string lamepath)
    {
        if (Path.GetFileName(lamepath).ToUpper() == "LAME.EXE")
        {
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            proc.StartInfo.CreateNoWindow = true;
            proc.EnableRaisingEvents = false;
            proc.StartInfo.FileName = lamepath;
            proc.StartInfo.RedirectStandardError = true;
            proc.StartInfo.UseShellExecute = false;
            proc.Start();

            string output = proc.StandardError.ReadLine();
            proc.WaitForExit();

            if (output.StartsWith("LAME") == true)
                return true;
            else
                return false;
        }
        else
            return false;
    }


    private string flac_path;
    public string FLAC_PATH { get { return flac_path; } }

    private string default_dir;
    public string DEFAULT_DIR { get { return default_dir; } }
    #endregion

    #region FLAC
    public bool SetFLACPath(string flacpath)
    {
        if (ValidateFLAC(flacpath) == true)
        {
            flac_path = flacpath;
            return true;
        }
        else
        {
            flac_path = "";
            return false;
        }
    }


    public bool ValidateFLAC(string flacpath)
    {
        if (Path.GetFileName(flacpath).ToUpper() == "FLAC.EXE")
        {
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            proc.StartInfo.CreateNoWindow = true;
            proc.EnableRaisingEvents = false;
            proc.StartInfo.FileName = flacpath;
            proc.StartInfo.Arguments = "-v";
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.UseShellExecute = false;
            proc.Start();

            string output = proc.StandardOutput.ReadToEnd();
            proc.WaitForExit();

            if (output.StartsWith("flac") == true)
                return true;
            else
                return false;
        }
        else
            return false;
    }

    public bool SaveSettings()
    {
        return true;
    }

    public bool LoadSettings()
    {
        return true;
    }
    #endregion



}

and the code to serialize it (Settings is an instance of Settings class above)

 //Serialization
        System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(Settings.GetType());
        TextWriter w = new StreamWriter(settingspath);
        x.Serialize(w, Settings);
        w.Close();

This just creates an xml file containing the xml header but no data. What am I doing wrong?
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:50:43+00:00Added an answer on May 13, 2026 at 4:50 pm

    You need read/write properties.

    In fact, from MSDN: http://msdn.microsoft.com/en-us/library/bdxxw552.aspx

    The Serialize method converts the public fields and read/write properties of an object into XML. It does not convert methods, indexers, private fields, or read-only properties. To serialize all of an object’s fields and properties, both public and private, use the BinaryFormatter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.