MVC4中与Active Directory相关的AppDomainUnloadedException

时间:2013-01-17 19:50:36

标签: asp.net-mvc-4 active-directory userprincipal

我有一个ASP.NET MVC应用程序。它在域上运行,我们通过调用UserPrincipal.Current来确定用户。大部分时间都很漂亮。每隔一段时间(可能是5次中的1次),并且只有在我将应用程序发布到IIS之后,它才会抛出AppDomainUnloadedException。

导致异常的代码的特定行是:

if (UserPrincipal.Current.SamAccountName != null && 
    _currentUserId != UserPrincipal.Current.SamAccountName) ...

调用堆栈的其余部分是:

mscorlib.dll!System.StubHelpers.StubHelpers.GetCOMHRExceptionObject(int hr, System.IntPtr pCPCMD, object pThis) + 0xe bytes 
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.ADStoreCtx.LoadDomainInfo() + 0x358 bytes 
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.ADStoreCtx.DnsDomainName.get() + 0x5e bytes   
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.ADStoreCtx.GetAsPrincipal(object storeObject, object discriminant = {Name = "UserPrincipal" FullName = "System.DirectoryServices.AccountManagement.UserPrincipal"}) + 0x17a bytes 
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.ADStoreCtx.FindPrincipalByIdentRefHelper(System.Type principalType, string urnScheme, string urnValue, System.DateTime referenceDate, bool useSidHistory) + 0x576 bytes   
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.ADStoreCtx.FindPrincipalByIdentRef(System.Type principalType, string urnScheme, string urnValue, System.DateTime referenceDate) + 0x35 bytes  
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(System.DirectoryServices.AccountManagement.PrincipalContext context, System.Type principalType, System.DirectoryServices.AccountManagement.IdentityType? identityType, string identityValue, System.DateTime refDate) + 0x9e bytes 
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(System.DirectoryServices.AccountManagement.PrincipalContext context, System.Type principalType, System.DirectoryServices.AccountManagement.IdentityType identityType, string identityValue) + 0x5b bytes 
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(System.DirectoryServices.AccountManagement.PrincipalContext context, System.DirectoryServices.AccountManagement.IdentityType identityType, string identityValue) + 0x1e bytes    
System.DirectoryServices.AccountManagement.dll!System.DirectoryServices.AccountManagement.UserPrincipal.Current.get() + 0xc1 bytes

经过大量的挖掘,并且由于异常的随机性,我得出的结论可能与此问题有关:

http://support.microsoft.com/kb/2683913

所以我安装了修补程序,正如预期的那样,问题就消失了。那是星期二。今天早上,异常再次开始。我确认已经安装了hotifx。我打开了模块加载消息并得到了:

'w3wp.exe': Loaded 'C:\Windows\SysWOW64\activeds.dll', Cannot find or open the PDB file.

所以我验证了.dll实际上是来自修补程序的那个。它是(大小和版本#s匹配)。

同时我得到了这个异常,我在事件日志中得到了这个事件:

A process serving application pool 'WebSitePool' suffered a fatal communication error with the Windows Process Activation Service. The process id was '7404'. The data field contains the error number.

错误中唯一的数据是:0x8007006D,我认为这只是意味着有一个致命的通信错误,错误已经说过......

幽默地,当弹出异常对话框时,它会说:“如果有这个例外的处理程序,程序可以安全地继续。”如果你的应用程序不需要UserPrincipal.Current,那么这是真的,但是在这个异常导致异常重新抛出后再次调用它,所以我会质疑它们在那里的“安全继续”断言。

现在,如果我重新运行应用程序,我不会遇到问题。除了发布之后,我还没有在任何时候发生这种情况。由于我们的设置和与其他项目的关系,这个应用程序必须在IIS下调试,这意味着我必须在每次更改代码时发布它,这意味着我通常在一天中看到这个(周二下午和昨天是例外)

我觉得很奇怪,从挖掘来看,这个bug似乎经常与ASP.NET MVC相关联,但我不相信我已经看到它与WinForms或ASP.NET有关...我可以看看这有多重要,但也许那里有关系。

我怀疑这是一个MS错误。我无法想象UserPrincipal.Current应该导致AppDomainUnloadedException的任何合法条件,但我想我会在Stackoverflow上点击这里......

0 个答案:

没有答案
相关问题