我在服务器上运行了一个 WCF 服务,偶尔(每月 1-2 次)它会抛出一个 COMException,并显示信息性消息“未知错误 (0x8005008)”。当我用谷歌搜索这个特定的错误时,我只得到了关于在 IIS 中创建虚拟目录时出现问题的线程。源代码与在 IIS 中创建虚拟目录无关。
DirectoryServiceLib.LdapProvider.Directory - CreatePost - Could not create employee for 195001010000,000000000000: System.Runtime.InteropServices.COMException (0x80005008): Unknown error (0x80005008) at System.DirectoryServices.PropertyValueCollection.PopulateList
当我捕获异常以在 WinDBG 中进行进一步分析时,我进行了内存转储。切换到正确的线程后,我执行了 !CLRStack 命令:
000000001b8ab6d8 000000007708671a [NDirectMethodFrameStandalone: 000000001b8ab6d8] Common.MemoryDump.MiniDumpWriteDump(IntPtr, Int32, IntPtr, MINIDUMP_TYPE, IntPtr, IntPtr, IntPtr)
000000001b8ab680 000007ff002808d8 DomainBoundILStubClass.IL_STUB_PInvoke(IntPtr, Int32, IntPtr, MINIDUMP_TYPE, IntPtr, IntPtr, IntPtr)
000000001b8ab780 000007ff00280812 Common.MemoryDump.CreateMiniDump(System.String)
000000001b8ab7e0 000007ff0027b218 DirectoryServiceLib.LdapProvider.Directory.CreatePost(System.String, DirectoryServiceLib.Model.Post, DirectoryServiceLib.Model.Presumptions, Services.Common.SourceEnum, System.String)
000000001b8ad6d8 000007fef8816869 [HelperMethodFrame: 000000001b8ad6d8]
000000001b8ad820 000007feec2b6c6f System.DirectoryServices.PropertyValueCollection.PopulateList()
000000001b8ad860 000007feec225f0f System.DirectoryServices.PropertyValueCollection..ctor(System.DirectoryServices.DirectoryEntry, System.String)
000000001b8ad8a0 000007feec22d023 System.DirectoryServices.PropertyCollection.get_Item(System.String)
000000001b8ad8f0 000007ff00274d34 Common.DirectoryEntryExtension.GetStringAttribute(System.String)
000000001b8ad940 000007ff0027f507 DirectoryServiceLib.LdapProvider.DirectoryPost.Copy(DirectoryServiceLib.LdapProvider.DirectoryPost)
000000001b8ad980 000007ff0027a7cf DirectoryServiceLib.LdapProvider.Directory.CreatePost(System.String, DirectoryServiceLib.Model.Post, DirectoryServiceLib.Model.Presumptions, Services.Common.SourceEnum, System.String)
000000001b8adbe0 000007ff00279532 DirectoryServiceLib.WCFDirectory.CreatePost(System.String, DirectoryServiceLib.Model.Post, DirectoryServiceLib.Model.Presumptions, Services.Common.SourceEnum, System.String)
000000001b8adc60 000007ff001f47bd DynamicClass.SyncInvokeCreatePost(System.Object, System.Object[], System.Object[])
我的结论是代码调用时它失败了 System.DirectoryServices.PropertyCollection.get_Item(System.String) 时它会失败。
所以在发出 !CLRStack -a 之后,我得到了这个结果:
000000001b8ad8a0 000007feec22d023 System.DirectoryServices.PropertyCollection.get_Item(System.String)
PARAMETERS:
this = <no data>
propertyName = <no data>
LOCALS:
<CLR reg> = 0x0000000001dcef78
<no data>
我的第一个问题是为什么它在属性名上没有显示任何数据?我对 Windbg 有点陌生。但是我在 = 0x0000000001dcef78 上执行了一个转储对象:
0:013> !do 0x0000000001dcef78
Name: System.String
MethodTable: 000007fef66d6960
EEClass: 000007fef625eec8
Size: 74(0x4a) bytes
File: C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
String: personalprescriptioncode
Fields:
MT Field Offset Type VT Attr Value Name
000007fef66dc848 40000ed 8 System.Int32 1 instance 24 m_stringLength
000007fef66db388 40000ee c System.Char 1 instance 70 m_firstChar
000007fef66d6960 40000ef 10 System.String 0 shared static Empty
>> Domain:Value 0000000000174e10:00000000019d1420 000000001a886f50:00000000019d1420 <<
因此,当源代码想要从 Active Directory(用于持久层)获取个人处方代码时,它会失败。回顾堆栈,它是在发出 Copy 方法时。 DirectoryServiceLib.LdapProvider.DirectoryPost.Copy(DirectoryServiceLib.LdapProvider.DirectoryPost)
所以查看源代码:
DirectoryPost postInLimbo = DirectoryPostFactory.Instance().GetDirectoryPost(LdapConfigReader.Instance().GetConfigValue("LimboDN"), idGenPerson.ID.UserId);
if (postInLimbo != null)
newPost.Copy(postInLimbo);
此代码正在 OU=limbo 中查找具有相同 UserId 的另一篇文章,如果找到,则将属性复制到新文章中。在这种情况下,它确实会失败,并显示个人处方代码。我查看了 OU=Limbo 下的 Active Directory,并且帖子存在于其中,属性personalprescriptioncode=31243。
问题 1:为什么它没有显示某些 PARAMETERS 和 LOCALS 的数据?是不是在创建 memorydump 之前清理过的 GC。
问题2:我还能做些什么来解决这个问题吗?