【问题标题】:Windows service fails start , Mixed Mode Assembly issueWindows 服务启动失败,混合模式程序集问题
【发布时间】:2014-09-23 14:30:02
【问题描述】:

我这里有一个独特的案例。

经过大量的试验和足够的谷歌搜索,我仍然无法解决这个问题。

我有一组运行时版本为“v2.0.50727”的库(第三方),我必须在我的 WINDOWS SERVICE 应用程序中使用它们(这里是键“Windows Service”),这需要 .Net v4.0 (v4.0.30319)。

我已经成功解决了到处描述的混合模式组装错误。

这里最丰富的解决方案来源之一:

What 'additional configuration' is necessary to reference a .NET 2.0 mixed mode assembly in a .NET 4.0 project?

安装后的服务,没有启动。 (抛出通用超时异常。)

The MyWindowsService service failed to start due to the following error: 
The service did not respond to the start or control request in a timely fashion.

事件查看器中的详细信息(在 windows 日志 > 应用程序下)指定 2 个来源

  1. .Net Runtime(详情如下)

    应用程序:MyWindowsService.exe 框架版本:v4.0.30319 说明:进程因未处理的异常而终止。 异常信息:System.Configuration.ConfigurationErrorsException 堆: 在 System.Configuration.ClientConfigurationSystem.EnsureInit(System.String) 在 System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(System.String) 在 System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(System.String) 在 System.Configuration.ConfigurationManager.get_AppSettings() 在 MyWindowsService..ctor() 在 MyWindowsService.Program.Main()

    1. 应用程序错误:(详情如下)

    错误应用程序名称:MyWindowsService.exe,版本:1.0.0.0,时间戳:0x53da4547 错误模块名称:KERNELBASE.dll,版本:6.1.7601.18409,时间戳:0x53159a86 异常代码:0xe0434352 故障偏移:0x0000c42d 错误进程 ID:0x3814 错误的应用程序启动时间:0x01cfacc646c337dc 错误的应用程序路径:c:\Src\bin\MyWindowsService.exe 错误模块路径:C:\Windows\syswow64\KERNELBASE.dll 报告 ID:8d72e05a-18b9-11e4-a80e-689423ef1889

这里重要的是,如果我从 app.config 中删除此配置 - 服务会正常启动(显然在运行时中断 - 因为混合模式程序集),而将其保留在配置中不会让它启动。

请指导我。 任何帮助将不胜感激。

附注: 1.到目前为止,我已经尝试了上面stackoverflow链接中指定的所有建议。

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/> </startup>
  1. 使用VS 2012,.Net Framework 4.0,windows 7

【问题讨论】:

  • 程序崩溃的异常是否与&lt;supportedRuntime&gt; 元素有关是非常值得怀疑的。它对您的应用程序设置不满意,没有一个体面的异常消息说明原因。在 Main() 方法中订阅 AppDomain.CurrentDomain.UnhandledException 事件,以便获得更好的报告。看起来你已经在这样做了,它需要工作。
  • @HansPassant:我试过你的建议,但没有比这更好的了。

标签: c# .net windows-services mixed-mode app-startup


【解决方案1】:

确定服务未启动原因的一个方法是将调试器连接到服务。

由于调试服务需要:

  1. 从服务控制管理器启动服务
  2. 在 VS 中使用调试“附加到进程”选项

由于您要连接到 OnStart 方法,您需要添加一个Thread.Sleep(5000);,以便在从服务控制管理器启动服务后给自己 5 秒的时间将调试器连接到服务。在 sleep 语句之后设置断点。

鉴于您是 .NET 运行时错误,您可能永远无法到达断点,因为它似乎在加载时出现问题。

您是否尝试创建一个使用相同第三方库的简单应用程序来验证 app.config 文件的正确设置?

尝试使用以下方法:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" />
  <supportedRuntime version="v2.0.50727" />
 </startup>
</configuration>

我找到了这个信息here

【讨论】:

  • 我尝试调试服务,bt 无法这样做,服务超时无论如何都会发生(即使我让线程休眠)。是的,我确实尝试从一个简单的应用程序调用相同的服务方法,并且它在指定的配置条目下运行良好。我也尝试了很多这样的 ... 工作正常 - 解决了混合模式错误。但是这里服务没有启动,在 app.config 中指定了这个条目。感谢您的帮助。
猜你喜欢
  • 2017-08-08
  • 1970-01-01
  • 1970-01-01
  • 2015-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-25
  • 2018-10-14
相关资源
最近更新 更多