You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Enterprise Library 5.0日志模块启动异常:断电后应用无法启动排查

问题分析:断电后客户端应用无法重启的异常根源

问题背景

  • 多客户端部署的应用,某次断电后无法重启
  • 事件日志显示与KERNELBASE.dll相关的错误,异常栈追踪到System.Xml.XmlException引发System.Configuration.ConfigurationErrorsException,最终导致Microsoft.Practices.EnterpriseLibrary.Logging.Logger调用失败
  • 排查操作:
    • 将客户端应用文件夹完整复制到开发机,可正常运行
    • 在客户端尝试检查app.config完整性、以管理员权限启动、移动应用目录、对比文件哈希等操作,均无法解决问题
    • 为Main方法添加try-catch块的新版本exe可正常启动,且未触发异常捕获;切回旧版本exe后,应用也恢复正常
  • 疑问:若为app.config问题,为何开发机无法复现?替换exe后异常消失的根本原因是什么?

事件日志信息

Faulting application name: MyApplication.exe, version: 7.3.0.14, time stamp: 0x626786ff
Faulting module name: KERNELBASE.dll, version: 6.1.7601.24561, time stamp: 0x5f76968d
Exception code: 0xe0434352
Fault offset: 0x0000c5af
Faulting process id: 0xeb4
Faulting application start time: 0x01d8d17277e726c1
Faulting application path: C:\Program Files (x86)\MyCompany\Visu\MyApplication.exe
Faulting module path: C:\Windows\syswow64\KERNELBASE.dll
Report Id: b5b2baf1-3d65-11ed-b8b3-00139548ead0

详细异常栈

Application: MyApplication.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Xml.XmlException
   at System.Xml.XmlTextReaderImpl.Throw(System.Exception)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlTextReader.Read()
   at System.Configuration.XmlUtil..ctor(System.IO.Stream, System.String, Boolean, System.Configuration.ConfigurationSchemaErrors)
   at System.Configuration.BaseConfigurationRecord.InitConfigFromFile()

Exception Info: System.Configuration.ConfigurationErrorsException
   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean)
   at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(System.Configuration.ConfigurationSchemaErrors)
   at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
   at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(System.Object, System.Configuration.Internal.InternalConfigEventArgs)

Exception Info: System.Configuration.ConfigurationErrorsException
   at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(System.Object, System.Configuration.Internal.InternalConfigEventArgs)
   at System.Configuration.Internal.InternalConfigRoot.OnConfigRemoved(System.Configuration.Internal.InternalConfigEventArgs)
   at System.Configuration.Internal.InternalConfigRoot.RemoveConfigImpl(System.String, System.Configuration.BaseConfigurationRecord)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(System.String, Boolean, Boolean, Boolean, Boolean, System.Object ByRef, System.Object ByRef)
   at System.Configuration.BaseConfigurationRecord.GetSection(System.String)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(System.String)
   at System.Configuration.ConfigurationManager.GetSection(System.String)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection.GetConfigurationSourceSection()
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceFactory.Create()
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer()
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet()
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current()
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer()
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(System.Object, System.String, Int32, Int32)
   at MyApplication.App.Main(System.String[])

原代码片段

[System.STAThreadAttribute()]
public static void Main(string[] args)
{
  Logger.Write("Application was started on:" + DateTime.Now, "Core", 100, 100);
  ...
}  

根本原因分析

  1. 本地配置缓存/文件临时损坏:断电可能导致客户端机器上的app.config文件出现部分读写损坏,或者.NET框架为提升性能缓存的配置临时文件(通常位于用户临时目录)失效、损坏。开发机复制的是完整未损坏的文件,因此无法复现问题。
  2. 配置系统缓存重置:添加try-catch的新版本exe启动时,即使没有触发捕获逻辑,应用启动流程的变化间接触发了.NET配置系统的缓存清理或重新加载。当切回旧版本时,损坏的缓存已经被替换为正常的配置内容,因此应用能正常启动。
  3. Logger初始化时机的脆弱性:原代码在Main方法开头直接调用Logger.Write,此时EnterpriseLibrary的配置加载逻辑还在执行中,一旦配置文件读取出现异常,就会直接抛出未处理异常导致崩溃。添加异常捕获后,应用有机会完成后续初始化流程,修复配置系统的异常状态。
  4. KERNELBASE.dll错误是表象:异常代码0xe0434352是.NET运行时未处理异常的通用标识,KERNELBASE.dll只是异常抛出时的底层调用模块,并非问题根源,真正的问题出在配置文件的XML解析环节。

总结

断电导致客户端本地的配置缓存或app.config文件临时损坏,这是开发机无法复现的核心原因;替换exe的操作触发了.NET配置系统的缓存刷新,修复了异常状态,因此旧版本也能恢复正常运行。

内容的提问来源于stack exchange,提问作者AFrueh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 02:45:38