I've been working on a Winforms application that currently contains a System.Collections.Specialized.StringCollection
user setting. On Windows, this code works to update and save the setting:
private void UpdateDirList() {
Properties.Settings.Default.SearchDirs.Clear();
Properties.Settings.Default.SearchDirs.AddRange(_searchDirs.ToArray());
Properties.Settings.Default.Save();
}
The relevant excerpt from user.config on a Windows machine:
<setting name="SearchDirs" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>C:\projects\a</string>
<string>C:\projects\b</string>
</ArrayOfString>
</value>
</setting>
When trying to run the same application under Mono, the <ArrayOfString>
element is missing, even when I've verified that the Properties.Settings.Default.SearchDirs
object does contain paths:
<setting name="SearchDirs" serializeAs="Xml">
<value />
</setting>
Does Mono not support StringCollection? Am I using it incorrectly?
Hm, I worked once with C# for Mono/Linux and Windows. It is not always the same!
I wonder why you use ToArray() at all - needed? And not ToList()? Does it work? List is IMHO preferred today, it can be used as IEnumerable and IList etc. ...
A workaround is sometimes needed - directories can be easily written as one string, separated by eg '|'- that is a character not allowed in a path - neither in Linux nor Windows.
var searchDirsCsv = string.Join("|", _searchDirs);
_searchDirs = searchDirsCsv.Split('|);
What do you think?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.