【发布时间】:2015-09-12 12:26:54
【问题描述】:
我刚刚发布了一个程序 (OptiKey),它传递用于在单个类中获取、设置和保存用户设置的 lambda:
从这个类传递 lambdas(从第 143 行开始): https://github.com/JuliusSweetland/OptiKey/blob/master/src/App.xaml.cs
到这堂课: https://github.com/JuliusSweetland/OptiKey/blob/master/src/Services/WindowManipulationService.cs
注意“set” lambda 更新设置的值(例如 Settings.Default.Whatever = X),然后调用 Settings.Default.Save()
我无法在本地复制崩溃,但我收到来自用户的崩溃报告,其中对 Save 的调用引发了异常,我通过从磁盘重新加载设置然后再次尝试保存来捕获和处理该异常。这不起作用,重试也抛出异常。
有人告诉我,即使用户没有使用病毒扫描程序(我认为这可能会锁定 user.settings 文件),也会发生这种情况。
有什么想法吗?这是我遇到的崩溃的最大原因,我不知道如何重现它!
The configuration file has been changed by another program. (C:\Users\Charlie Sheen\AppData\Roaming\JuliusSweetland\OptiKey.exe_Url_2dm1ifc0wqzcnmfgnsyhbssrcdx5zgbz\2.0.5.0\user.config)
<SerializableException xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ExtendedInformation>
<HResult>-2146232828</HResult>
</ExtendedInformation>
<InnerException>
<ExtendedInformation>
<BareMessage>Failed to save settings: The configuration file has been changed by another program. (C:\Users\Charlie Sheen\AppData\Roaming\JuliusSweetland\OptiKey.exe_Url_2dm1ifc0wqzcnmfgnsyhbssrcdx5zgbz\2.0.5.0\user.config)</BareMessage>
<Line>0</Line>
<Errors>System.Configuration.ConfigurationException[]</Errors>
<HResult>-2146232062</HResult>
</ExtendedInformation>
<InnerException>
<ExtendedInformation>
<BareMessage>The configuration file has been changed by another program.</BareMessage>
<Filename>C:\Users\Charlie Sheen\AppData\Roaming\JuliusSweetland\OptiKey.exe_Url_2dm1ifc0wqzcnmfgnsyhbssrcdx5zgbz\2.0.5.0\user.config</Filename>
<Line>0</Line>
<Errors>System.Configuration.ConfigurationException[]</Errors>
<HResult>-2146232062</HResult>
</ExtendedInformation>
<Message>The configuration file has been changed by another program. (C:\Users\Charlie Sheen\AppData\Roaming\JuliusSweetland\OptiKey.exe_Url_2dm1ifc0wqzcnmfgnsyhbssrcdx5zgbz\2.0.5.0\user.config)</Message>
<Source>System.Configuration</Source>
<StackTrace> at System.Configuration.MgmtConfigurationRecord.SaveAs(String filename, ConfigurationSaveMode saveMode, Boolean forceUpdateAll)
at System.Configuration.Configuration.SaveAsImpl(String filename, ConfigurationSaveMode saveMode, Boolean forceSaveAll)
at System.Configuration.ClientSettingsStore.WriteSettings(String sectionName, Boolean isRoaming, IDictionary newSettings)</StackTrace>
<TargetSite>Void SaveAs(System.String, System.Configuration.ConfigurationSaveMode, Boolean) @ System.Configuration.MgmtConfigurationRecord</TargetSite>
<Type>System.Configuration.ConfigurationErrorsException</Type>
</InnerException>
<Message>Failed to save settings: The configuration file has been changed by another program. (C:\Users\Charlie Sheen\AppData\Roaming\JuliusSweetland\OptiKey.exe_Url_2dm1ifc0wqzcnmfgnsyhbssrcdx5zgbz\2.0.5.0\user.config)</Message>
<Source>System</Source>
<StackTrace> at System.Configuration.ClientSettingsStore.WriteSettings(String sectionName, Boolean isRoaming, IDictionary newSettings)
at System.Configuration.LocalFileSettingsProvider.SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection values)
at System.Configuration.SettingsBase.SaveCore()
at System.Configuration.SettingsBase.Save()
at System.Configuration.ApplicationSettingsBase.Save()
at JuliusSweetland.OptiKey.App.<App_OnStartup>b__18(Double t) in c:\Users\Julius\Documents\GitHub\OptiKey\src\App.xaml.cs:line 251
at JuliusSweetland.OptiKey.Services.WindowManipulationService.PersistDockThickness() in c:\Users\Julius\Documents\GitHub\OptiKey\src\Services\WindowManipulationService.cs:line 1003
at JuliusSweetland.OptiKey.Services.WindowManipulationService.PersistSizeAndPosition() in c:\Users\Julius\Documents\GitHub\OptiKey\src\Services\WindowManipulationService.cs:line 1026
at JuliusSweetland.OptiKey.Services.WindowManipulationService.ApplyAndPersistSizeAndPosition(Rect rect) in c:\Users\Julius\Documents\GitHub\OptiKey\src\Services\WindowManipulationService.cs:line 523</StackTrace>
<TargetSite>Void WriteSettings(System.String, Boolean, System.Collections.IDictionary) @ System.Configuration.ClientSettingsStore</TargetSite>
<Type>System.Configuration.ConfigurationErrorsException</Type>
</InnerException>
<Message>Exception has been thrown by the target of an invocation.</Message>
<Source>mscorlib</Source>
<StackTrace> at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)</StackTrace>
<TargetSite>System.Object InvokeMethod(System.Object, System.Object[], System.Signature, Boolean) @ System.RuntimeMethodHandle</TargetSite>
<Type>System.Reflection.TargetInvocationException</Type>
</SerializableException>
在代码中的其他几个地方也可以访问(获取/设置+保存)FYI 设置 - 可能同时进行,但我认为这不会发生。
【问题讨论】: