Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

I just had a test and it looks like the setting string can hold exactly 32,767 bytes of text (2 bytes worth of bytes).Too much of a coincidence not to conclude it's a design limit.

There is however a XML document setting type (click on "Browse"). This could be a way to work around the limit.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top