c# - Windows 服务启动失败,混合模式程序集问题

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

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

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

我有一组运行时版本为“v2.0.50727”的库(第三方),我必须在我的 WINDOWS SERVICE 应用程序中使用它们(这里是键“Windows 服务”),这需要 .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 logs > Application 下)指定 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 报告编号: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

最佳答案

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

由于调试服务需要:

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

因为您想要连接到 OnStart 方法,您需要添加一个 Thread.Sleep(5000); 以便在从服务控制经理。在 sleep 语句之后设置一个断点。

鉴于您是 .NET 运行时错误,您可能永远不会遇到 breakpoing,因为加载似乎有问题。

您是否尝试创建一个使用相同第三方库的简单应用程序来验证 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

关于c# - Windows 服务启动失败,混合模式程序集问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25062391/

相关文章:

javascript - RegisterJsObject CefSharp 不起作用

c# - Google Drive 简单 API 访问授权失败

c# - 无法更新 MSI 安装的 Windows 服务

c# - 如何将 PrincipalContext 与 MVC Web 应用程序一起使用

c# - 内存记录过多的 LINQ to SQL

c# - 内存不足时释放的动态变量?

java - Tomcat windows服务无法访问网络驱动器

c#-4.0 - Office 互操作在 Windows 服务中不起作用

c# - 我如何编写一个 C# 循环来计算 future 5 年每年增加 2% 的学费

.net - TypeAccessException : Attempt by method . .. 访问类型 ... 失败