TypeInitializationException启动Windows服务,因为配置部分不能被创建时部分、TypeInitializationException、Windows

2023-09-03 02:24:44 作者:江湖书生

我有一个奇怪的错误特定的Windows Server 2008 R2的计算机启动Windows服务时(它与其他的2008 R2机器)上。该服务使用 Common.Logging 和 log4net的。然而,这种特定的机器上不能创造Common.Logging的配置节处理程序。

它失败,出现以下堆栈跟踪(格式为更好的可读性)。最让我惊讶的是 SecurityException异常。是什么原因?

有没有人有一个线索?

  System.TypeInitializationException:的类型初始
    MyWindowsService.Program'引发了异常。
--->
Common.Logging.ConfigurationException:无法获取配置
    从配置节通用/日志Common.Logging。
--->
System.Configuration.ConfigurationErrorsException:出错创建
    对于普通/日志记录配置节处理程序:请求失败。
    (C:\路径\ MyWindowsService.exe.Config线7)
--->
System.Security.SecurityException:请求失败。
在System.RuntimeTypeHandle.CreateInstance(
    RuntimeType型,布尔publicOnly,布尔NOCHECK,布尔和放大器; canBeCached,
    RuntimeMethodHandleInternal和放大器;构造函数,布尔和放大器; bNeedSecurityCheck)
在System.RuntimeType.CreateInstanceSlow(布尔publicOnly,布尔skipCheckThis,
    布尔fillCache)
在System.RuntimeType.CreateInstanceDefaultCtor(布尔publicOnly,
    布尔skipVisibilityChecks,布尔skipCheckThis,布尔fillCache)
在System.Activator.CreateInstance(类型类型,布尔非公开)
在System.Configuration.TypeUtil.CreateInstanceWithReflectionPermission(类型类型)
在System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.Init(
    RuntimeConfigurationRecord configRecord,FactoryRecord factoryRecord)
在System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.InitWithRestrictedPermissions(
    RuntimeConfigurationRecord configRecord,FactoryRecord factoryRecord)
在System.Configuration.RuntimeConfigurationRecord.CreateSectionFactory(
    FactoryRecord factoryRecord)
在System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(
    字符串configKey,布尔和放大器; isRootDeclaredHere)
---内部异常堆栈跟踪的结尾---
 

它继续:

 在System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(
    字符串configKey,布尔和放大器; isRootDeclaredHere)
在System.Configuration.BaseConfigurationRecord.GetSectionRecursive(
    字符串configKey,布尔getLkg,布尔的checkPermission,布尔getRuntimeObject,
    布尔requestIsHere,对象和放大器;结果,对象和放大器; resultRuntimeObject)
在System.Configuration.BaseConfigurationRecord.GetSection(字符串configKey)
在System.Configuration.ConfigurationManager.GetSection(字符串sectionName)
在Common.Logging.LogManager<> c__DisplayClass6< BuildLoggerFactoryAdapter> b__3()
在Common.Logging.Configuration.ArgUtils<> c__DisplayClass13<后卫> b__12()
在Common.Logging.Configuration.ArgUtils.Guard [T](Function`1功能,
    字符串的MessageFormat,对象[]参数)
---内部异常堆栈跟踪的结尾---

在Common.Logging.Configuration.ArgUtils.Guard [T](Function`1功能,
    字符串的MessageFormat,对象[]参数)
在Common.Logging.LogManager.BuildLoggerFactoryAdapter()
在Common.Logging.LogManager.get_Adapter()
在Common.Logging.LogManager.GetLogger(类型类型)
在MyWindowsService.Program..cctor()
---内部异常堆栈跟踪的结尾---

在MyWindowsService.Program.Main(字串[] args)
 

我的配置是这样的(它的Common.Logging部分反正)。

 < configSections>
  < sectionGroup名=普通>
    <节名称=登陆
             TYPE =Common.Logging.ConfigurationSectionHandler,Common.Logging/>
  < / sectionGroup>
< / configSections>

<普通>
  <记录>
    < factoryAdapter
     TYPE =Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,Common.Logging.Log4net>
      <精氨酸键=configType值=内联/>
    < / factoryAdapter>
  < /记录>
< /常见>
 
3G智能尽显无敌性价比 华为U8800评测

解决方案

我已经看到了奇怪的事情发生了,当客户从我们的网站上下载我们的ZIP(ASP.NET应用程序)文件。由于安全功能此文件来自其他计算机,可能被阻止以帮助保护该计算机。

疏通文件解决了所有奇怪的问题,这可以解释为什么这只发生OM的部分的具有完全相同的配置的计算机上。

疏通选项显示只有当文件实际上挡在文件属性对话框的常规选项卡:

I have a strange error on a specific Windows Server 2008 R2 machine (it works on other 2008 R2 machines) when starting a Windows Service. The service uses Common.Logging and log4net. However, on this specific machine the config section handler for Common.Logging can not be created.

It fails with the following stack traces (formatted for better readability). What surprises me most is the SecurityException. What can cause this?

Does anyone have a clue?

System.TypeInitializationException: The type initializer for
    'MyWindowsService.Program' threw an exception.
--->
Common.Logging.ConfigurationException: Failed obtaining configuration for
    Common.Logging from configuration section 'common/logging'.
--->
System.Configuration.ConfigurationErrorsException: An error occurred creating
    the configuration section handler for common/logging: Request failed.
    (C:\Path\MyWindowsService.exe.Config line 7)
--->
System.Security.SecurityException: Request failed.
at System.RuntimeTypeHandle.CreateInstance(
    RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached,
    RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis,
    Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly,
    Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Configuration.TypeUtil.CreateInstanceWithReflectionPermission(Type type)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.Init(
    RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.InitWithRestrictedPermissions(
    RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
at System.Configuration.RuntimeConfigurationRecord.CreateSectionFactory(
    FactoryRecord factoryRecord)
at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(
    String configKey, Boolean& isRootDeclaredHere)
--- End of inner exception stack trace ---

It continues with:

at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(
    String configKey, Boolean& isRootDeclaredHere)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(
    String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject,
    Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at Common.Logging.LogManager.<>c__DisplayClass6.<BuildLoggerFactoryAdapter>b__3()
at Common.Logging.Configuration.ArgUtils.<>c__DisplayClass13.<Guard>b__12()
at Common.Logging.Configuration.ArgUtils.Guard[T](Function`1 function,
    String messageFormat, Object[] args)
--- End of inner exception stack trace ---

at Common.Logging.Configuration.ArgUtils.Guard[T](Function`1 function,
    String messageFormat, Object[] args)
at Common.Logging.LogManager.BuildLoggerFactoryAdapter()
at Common.Logging.LogManager.get_Adapter()
at Common.Logging.LogManager.GetLogger(Type type)
at MyWindowsService.Program..cctor()
--- End of inner exception stack trace ---

at MyWindowsService.Program.Main(String[] args)

My configuration looks like this (the Common.Logging part of it anyway).

<configSections>
  <sectionGroup name="common">
    <section name="logging"
             type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
  </sectionGroup>
</configSections>

<common>
  <logging>
    <factoryAdapter
     type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter,Common.Logging.Log4net">
      <arg key="configType" value="INLINE" />
    </factoryAdapter>
  </logging>
</common>

解决方案

I've seen strange things happening when customers downloaded our zip (ASP.NET application) file from our website. Because of the security feature "This file came from another computer and might be blocked to help protect this computer".

Unblocking the files solved all strange problems, this would explain why this is only happening om some computers with exactly the same configuration.

The Unblock option is shown only when the file is actually blocked in the General tab of the file properties dialog:

 
精彩推荐