【发布时间】:2013-07-17 14:31:31
【问题描述】:
我在一台 32 位 windows server 2003 机器上安装了一个 C# windows 服务,我想调试它。
我遇到的问题是日志文件错误消息告诉我以下内容:
System.NullReferenceException: Object reference not set to an instance of an object.
at VideoProcessor.ResetCameraProperties(DataServiceObject dso)
at VideoProcessor.AddServer(DataServiceObject dso)
at VideoProcessor.LoadServers()
at VideoProcessor.Start()
atVideoServerComponent.Connect()
函数ResetCameraProperties的实际代码是:
protected void ResetCameraProperties(DataServiceObject dso)
{
// Find the CameraType.
//Type videoCameraType = TypeManager.Instance["XFire.Common.VideoObjects.VideoServer"];
if (_videoCameraType == null) return;
//Load cameras from the Data Service Layer
string whereClause = "ServerID = ?";
object[] args = new object[] { dso["ObjectID"] };
IDataServiceCollection videoCameraDsoCollection = ClientServerConnection.Instance.FindCollection(_videoCameraType, whereClause, args, null, CollectionOptions.FilterByPartitionResponsibility) as IDataServiceCollection;
if (videoCameraDsoCollection == null || 0 == videoCameraDsoCollection.Count)
return;
videoCameraDsoCollection.LoadContainerOnEnumeration = false;
foreach (DataServiceObject camera in videoCameraDsoCollection)
{
if (!(bool)dso[RecorderKey.Online] && (int)dso[RecorderKey.VideoServerAlarm] == (int)VideoServerComponent.GetVideoServerAlarm("Offline"))
{
// If the server is disconnected, then we know everything should be offline.
camera[CameraKey.VideoCameraAlarm] = VideoServerComponent.GetEnumValueOfType("XFire.Common.VideoObjectDefinitions.VideoCameraAlarm", "Unknown");
camera[CameraKey.Videoloss] = true;
}
else if ((bool)dso[RecorderKey.Online] && (int)dso[RecorderKey.VideoServerAlarm] == (int)VideoServerComponent.GetVideoServerAlarm("Online"))
{
camera[CameraKey.VideoCameraAlarm] = VideoServerComponent.GetEnumValueOfType("XFire.Common.VideoObjectDefinitions.VideoCameraAlarm", "Normal");
camera[CameraKey.Videoloss] = false;
}
// Save the camera.
ServerResult result = ClientServerConnection.Instance.PersistObject(camera, null);
if (result.Fault != null)
{
if (VideoTrace.TraceError) Trace.WriteLine(result.Fault.Message);
}
}
-
我打开了windbg并做了File-->Attach to process
-
我已使用此处概述的步骤在上述函数中设置断点:https://docs.microsoft.com/en-us/archive/blogs/alejacma/managed-debugging-with-windbg-preparing-the-environment
-
当断点被击中时,我使用 F10 向前走,但我看到的只是以下内容:
设置断点:bp 05A0A260 [VideoProcessor.*ResetCameraProperties (XFire.Common.DataServiceLayer.DataServiceObject)] 添加挂起的断点... 0:024> 克 DriverWindowsService.OnStop 服务停止... 断点 0 命中 eax=00000001 ebx=00902870 ecx=00a1e020 edx=01066e78 esi=00affb48 edi=01066e78 eip=05a0a260 esp=0674e68c ebp=0674e6b0 iopl=0 nv up ei pl nz na po nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202 05a0a260 55 推送 ebp 0:024> p eax=00000001 ebx=00902870 ecx=00a1e020 edx=01066e78 esi=00affb48 edi=01066e78 eip=05a0a261 esp=0674e688 ebp=0674e6b0 iopl=0 nv up ei pl nz na po nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202 05a0a261 8bec mov ebp,esp 0:024> p eax=00000001 ebx=00902870 ecx=00a1e020 edx=01066e78 esi=00affb48 edi=01066e78 eip=05a0a263 esp=0674e688 ebp=0674e688 iopl=0 nv up ei pl nz na po nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202 05a0a263 57 推送编辑
目前这对我来说没什么意义(我是一个windbg新手)
-
我有 Windows 服务的 pdb 文件(我从 Visual Studio 调试输出文件夹中获得)并将其复制到我的目标计算机的文件夹 C:\Symbols 中。
-
在 winDbg 中,我做了 File-->Symbol FIle path 并将其设置为我复制过来的这个 pdb 文件的位置。我的符号路径如下: C:\symcache;C:\Symbols;srvc:\symcachehttp://msdl.microsoft.com/download/symbols
-
在 Windbg 中,我执行了 View-->Watch 并输入了上述函数内部的变量名称 (videoCameraType)。但我收到以下错误:
*** 您指定了一个不合格的符号,或者您的调试器 *** *** 没有完整的符号信息。不合格符号*** *** 分辨率默认关闭。请指定一个*** *** 完全限定符号模块!符号名,或启用解析 *** 通过键入“.symopt- 100” *** 不合格符号。注意 *** *** 使用网络符号启用不合格的符号解析 *** *** 符号路径中的服务器共享可能会导致调试器 *** *** 出现错误时会长时间挂起 *** *** 输入符号名称或网络符号服务器已关闭。 ***
*** 要使某些命令正常工作,您的符号路径 *** *** 必须指向具有完整类型信息的 .pdb 文件。 ***
*** 某些 .pdb 文件(例如公共 OS 符号)不会 *** *** 包含所需的信息。联系该组*** *** 如果您需要此命令,则为您提供这些符号 *** *** 工作。 ***
*** 引用的类型:_videoCameraType ***
如何查看变量并大致了解我的代码中发生了什么???? 如果有帮助,我也有 Windows 服务的源代码。
谢谢
【问题讨论】:
-
对这篇文章的几个建议,1) 你能在这个问题中添加 C# 标签吗? 2)你能修复你的代码缩进吗? 3)错字:这对我来说意味着nothign