对于我最新的WPF应用程序,我一直使用System.Collections.Specialized.StringCollection
保存和加载字符串。我当前的系统在“调试和发行”中的工作原理很不错,但是当部署到ClickOnce时,只要涉及到设置(加载或保存),应用程序就会崩溃!但是,System.Collections.Specialized.StringCollections
本身即使没有设置也可以正常工作。
是什么原因导致这些崩溃?
这是我的系统:
public static void SaveCharacter(string code)
{
// Declare a blank StringCollection
StringCollection strings = new StringCollection();
// Convert the current settings StringCollection into an array and combine with the blank one
if (Settings.Default.SavedCharacters.Count > 0)
{
string[] tempArr= new string[Settings.Default.SavedCharacters.Count];
Settings.Default.SavedCharacters.CopyTo(tempArr, 0);
strings.AddRange(tempArr);
}
// Add the new string to the list
strings.Add(code);
// This new list is now saved as the setting itself
Settings.Default.SavedCharacters = strings;
Settings.Default.Save();
}
public static void RestoreCharacters()
{
foreach (string str in Settings.Default.SavedCharacters)
{
CreateCharacter(str, "l" + ID.ToString()); // This function works fine
ID++; // So does this variable (it's a public static)
}
}
P.S。我尝试了类似的系统,其中有List<string>
个项目,但没有骰子。不过,涉及strings
,bools
和ints
的其他设置也可以正常工作。
P.P.S。旁注,有没有人知道如何组合System.Collections.Specialized.StringCollections
而不必将其转换为数组?
答案 0 :(得分:0)
回答我自己的问题,以防其他人陷入这种令人讨厌的错误中!必须先创建要使用的用户设置,然后才能使用必须为public static void main(String[] args) throws BootstrapException {
PayaraMicro.getInstance()
.setDeploymentDir(new File("my_project_path/target"))
.setHttpAutoBind(true)
.bootStrap();
}
的用户设置。例如:
newed()
在保存此类集合时,只需使用StringCollection foo = Settings.Default.SavedCharacters;
即可正常工作!