当我的Wpf应用程序启动时,我在Settings.Designer.cs中收到BindingFailureException
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public global::System.Collections.Specialized.StringCollection Projects {
get {
return ((global::System.Collections.Specialized.StringCollection)(this["Projects"]));
}
set {
this["Projects"] = value;
}
}
使用以下消息:
The assembly with display name 'System.XmlSerializers' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'System.XmlSerializers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
在我的MainWindow代码背后,我在window_loaded
上执行以下操作:
try
{
if (Properties.Settings.Default.Projects==null)
Properties.Settings.Default.Projects=new StringCollection( );
var removalList = new List<string>( );
foreach (string project in Properties.Settings.Default.Projects)
{
if (System.IO.File.Exists(project))
OpenProject(project);
else
{
removalList.Add(project);
}
}
foreach (string missingProject in removalList) //so that we are not removing an item while iterating
{
Properties.Settings.Default.Projects.Remove(missingProject);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString( ));
}
同样在window_closing
try
{
//TODO: save prompt
Properties.Settings.Default.Save( );
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString( ));
}
这也引发了同样的异常。为什么我会在访问Properties.Settings
时遇到异常?
答案 0 :(得分:2)
在我的经历中,这种例外并不是那么不寻常。什么 不寻常的是,在您的情况下(显然)未处理异常。通常,(根据我的经验),异常会被其他机制静默捕获和处理。
你有可能在VS调试器中使用'抛出异常时中断'来运行它吗?该设置在Debug - &gt;下。例外......顺便说一句。