【问题标题】:how can you debug this error? The <service name> service could not be started. The service did not report an error你怎么能调试这个错误? <服务名称> 服务无法启动。服务没有报错
【发布时间】:2010-11-15 08:40:18
【问题描述】:

服务无法启动。服务没有报错。

每当我在命令行中安装 Windows 服务项目时都会遇到此错误。我的代码中确实存在错误,但是如何通过这种错误消息找到该错误?

【问题讨论】:

    标签: windows-services installation


    【解决方案1】:

    如果您安装了 Visual Studio 并且正在使用 .NET,请在 OnStart() 函数中调用 System.Diagnostics.Debugger.Break()。当您的服务启动时,系统会提示您调试该服务。选择 Visual Studio 选项,您将进入程序断点所在的调试器。您可以从那里正常调试。

    【讨论】:

      【解决方案2】:

      添加错误处理块(捕获 UnhandledException 或只是尝试/捕获可疑代码周围的块)并记录它(我使用 Trace 或 Debug - 您可以使用 DebugView 查看这些消息)。

      为了让服务经理知道存在错误(只是为了帮助用户),您可以:

      service.ExitCode = 1064; //ERROR_EXCEPTION_IN_SERVICE - just example
      

      其中“服务”是您的服务对象。

      【讨论】:

      • 此 ExitCode 将出现在 net start 输出中,或从服务 MMC 窗口启动。
      【解决方案3】:

      你的服务的 OnStart() 方法有异常,添加

       try{...} 
       catch(Exception ex)
       {
           //write to file ex.ToString();
       }
      

      并将您的异常记录到文件中

      【讨论】:

      • 使用 windows 事件日志... EventLog.WriteEntry(String.Format("WcfServiceHostTest \n 异常消息: {0}\nTrace: {1}", ex.Message, ex.StackTrace), EventLogEntryType.Error);
      猜你喜欢
      • 1970-01-01
      • 2011-06-08
      • 2018-10-01
      • 1970-01-01
      • 2011-05-23
      • 2011-07-25
      • 1970-01-01
      • 2014-03-13
      • 1970-01-01
      相关资源
      最近更新 更多