What does this exception message mean?
I am writing an app (something like Notepad) in C#. I'm using Properties.Settings
class to save user preferences. It was working fine until suddenly when it started showing this exception message anytime I try to run it.
Configuration system failed to initialize
I noticed that the error originated from this part of the code:
private void TextPad_Load(object sender, EventArgs e)
{
rtbText.WordWrap = Properties.Settings.Default.WordWrap;
rtbText.Font = Properties.Settings.Default.DefFont;
rtbText.ForeColor = Properties.Settings.Default.ForeColor;
rtbText.BackColor = Properties.Settings.Default.BackColor;
if (Properties.Settings.Default.ShowLast)
{
OpenLocalFile(Properties.Settings.Default.LastFile);
}
// There are other lines which are not relevant to this question
}
I moved the supposedly lines to the form constructor immediately after InitializeComponent();
but I still got the same error.
Actually the compiler is telling the error originates from this in Settings.Designer.cs:
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool WordWrap {
get {
return ((bool)(this["WordWrap"]));
}
set {
this["WordWrap"] = value;
}
If I remove rtbText.WordWrap = Properties.Settings.Default.WordWrap;
from TextPad_Load
, it shows
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Consolas, 9.75pt")]
p开发者_开发技巧ublic global::System.Drawing.Font DefFont {
get {
return ((global::System.Drawing.Font)(this["DefFont"]));
}
set {
this["DefFont"] = value;
}
The only solution now is either to remove those lines from TextPad_Load
(which makes the idea loading user preferences useless) or starting a new project (which I have done, anyway). Can someone please explain what the exception message means and maybe I can get a solution (in case I run into it again)? Microsoft VS Help is not giving me anything tangible.
Thanks
It might help to throw away your existing .config files.
After changes in the Properties.Settings the old file might not be valid any more (changed names, or removed items no longer recognized).
Note that user scoped settings are stored in (drive):\Users(usr)\AppData\Local\Microsoft...something
精彩评论