Is there a maximum size for application settings?
Asked Answered
S

2

10

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?

Slinky answered 8/12, 2013 at 18:18 Comment(6)
the code u specified doesn't makes any much sense, please be a little more specific!Melaniamelanic
The code is just for generating the same dummydata I used. Not relevant to the problem.Slinky
I have verified the same behaviour in as far as the Visual Studio UI for creating settings also ignores any pasted content longer than the aforementioned 310 rows. Making the rows shorter increases the total number of rows that are accepted; so I conclude that it's the number of characters rather than the number of rows which is significant. I did have to inquire further as to what OP was trying to do so suggest some more explanation should be added to the question.Brietta
i just ran & tested, all 500 lines thr!Melaniamelanic
That is even stranger I think.Slinky
RelatedMulholland
C
6

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.

Cambric answered 8/12, 2013 at 19:18 Comment(1)
Yep, this seems to be the issue. Did not know about the textbox limitation. Ty sir.Slinky
V
0

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.

Vuillard answered 8/12, 2013 at 19:5 Comment(3)
Thanks for the suggestion, still annoying that it fails silently like this imo.Slinky
@JohanLarsson Indeed it's pretty strange to see that the string type limited to 2 bytes in length instead of the usual 32 bytes,and even more so because it looks like string is supposed to be the standard string datatype from mscorlib.dll. I suspect the limit comes from a field limit in the setting tab rather than an actual datatype limit. Have you tried loading the data in the settings programically?Vuillard
Yep, tried to edit the file in notepad like Fredou suggested and it worked.Slinky

© 2022 - 2024 — McMap. All rights reserved.