Search code examples
c#application-settings

Is there a maximum size for application settings?


Background: I had a large xml string in a Setting and it failed to deserialize. The XmlSerializer complained it was not valid xml. When looking at the string in Project > Settings it looked truncated.

I googled for if there is a limit in size for application settings but did not find anything.

Then I tried to reproduce it using dummydata generated with the following code:

[Test]
public void DumpDummyData()
{
    int n = 500;
    var s = new string('a', 100);
    using (FileStream stream = File.OpenWrite(@"C:\Temp\"+n+".txt"))
    {
        using (var writer = new StreamWriter(stream))
        {

            for (int i = 0; i < n; i++)
            {
                writer.WriteLine( i +" " +s);
            }
        }
    }
}

The string is truncated at row 310 when pasting the contents of the file in a setting. Tried it in two different projects.

My question is what is the limit for app settings size?


Solution

  • so I did a quick test

    using System;
    
    namespace ConsoleApplication1
    {
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Properties.Settings.Default.test.Length);
            Console.ReadKey();
        }
    }
    }
    

    the test setting contains a long text, over 50,000 characters

    it does work.

    what i did is I changed the app.config manually not from the visual studio solution properties setting.

    I assume the setting screen use default maximum value. default maximum value for a textbox is 32,767 characters.

    so can you try your test again by changing the app.config by yourself?

    do not use the visual studio solution properties setting screen.