简体   繁体   English

调试Topshelf服务

[英]Debugging Topshelf Service

I am using Topshelf to create a Windows service which uses the chrome Selenium driver to manipulate and parse various webpages. 我正在使用Topshelf创建Windows服务,该服务使用chrome Selenium驱动程序来处理和解析各种网页。

While the service code runs fine from a normal (NetCore2) console test application, there's a problem when it runs under the Win32 console app that Topshelf requires. 尽管该服务代码可以从常规(NetCore2)控制台测试应用程序正常运行,但是当它在Topshelf所需的Win32控制台应用程序下运行时仍然存在问题。

Unfortunately, I haven't been able to figure out how to debug into the underlying service code. 不幸的是,我无法弄清楚如何调试底层的服务代码。 The VS2017 debugger appears to be attached to the Topshelf console app, but won't let me step into the underlying service code, which is in a separate NetStandard2 class library. VS2017调试器似乎已附加到Topshelf控制台应用程序,但不允许我进入底层的服务代码,该代码位于单独的NetStandard2类库中。 Specifically, when I come to this line in the Topshelf console app: 具体来说,当我在Topshelf控制台应用程序中看到以下内容时:

var scanEntry = _scanner.Run();

where _scanner is an instance of the object that does the actual scanning, I can't step into the code (ie, F11 just steps over the line). _scanner是执行实际扫描的对象的实例,而我无法进入代码(即F11只是越过该行)。

I tried inserting the following line into the class library scanning code: 我尝试将以下行插入类库扫描代码:

System.Diagnostics.Debugger.Launch();

but it doesn't do anything; 但是它什么也没做。 the code just keeps merrily executing along. 该代码只是保持愉快地执行。

I suspect this is related to the fact that the scanning code is running in a separate process that Topshelf launches. 我怀疑这与以下事实有关:扫描代码在Topshelf启动的单独进程中运行。 But I haven't been able to figure out how to identify it through Visual Studio's Attach to Process mechanism. 但是我还无法弄清楚如何通过Visual Studio的“附加到进程”机制来识别它。

Pointers on how to debug the underlying service code when it's running under Topshelf would be much appreciated. 有关在Topshelf下运行基础服务代码时如何调试基础服务代码的指针将不胜感激。

Additional Info 附加信息

When I tried stopping on that _scanner.Run() line, and using the context menu to single step into the class library code (rather than using F11), I got prompted to turn off Just My Code, which I did. 当我尝试停止在_scanner.Run()行上,并使用上下文菜单单步进入类库代码(而不是使用F11)时,系统提示我关闭“我的代码”。 The VS debugger then tried to step into the class library code, but complained that it couldn't find the library's symbol file (*.pdb). 然后,VS调试器尝试进入类库代码,但抱怨找不到该库的符号文件(* .pdb)。

Which is really weird, because a symbol file with that name exists in the bin folder for the Topshelf console app. 这真的很奇怪,因为在Topshelf控制台应用程序的bin文件夹中存在具有该名称的符号文件。

I tried manually opening the pdb file from the bin folder, but got an error message that "A matching symbol file was not found in this folder". 我尝试从bin文件夹中手动打开pdb文件,但收到一条错误消息“在此文件夹中找不到匹配的符号文件”。

Is this related to trying to debug a NetStandard2 class library from within a plain old Net console app? 这是否与尝试从普通的旧Net控制台应用程序中调试NetStandard2类库有关?

Okay, turns out the problem was related to debugging a mixed NetStandard and NetOriginal code base... 好的,原来问题出在调试混合的NetStandard和NetOriginal代码库。

NetStandard class libraries, by default, do not generate debug symbol information usable by NetOriginal apps. 默认情况下,NetStandard类库不会生成NetOriginal应用程序可用的调试符号信息。 You have to go into Project Properties -> Build -> Advanced and change the type of debug information being generated from Portable to Full. 您必须进入Project Properties-> Build-> Advanced并将正在生成的调试信息的类型从Portable更改为Full。

Once I made this change I was able to step into the class library code as per usual. 进行此更改后,我便可以照常进入类库代码。

I found this at a matching symbol file was not found in this folder 在此文件夹中找不到匹配的符号文件中找到此文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM