C# System.Runtime.InteropServices.COMException:在缓存中找不到目录属性
当我们试图通过检索属性PasswordExpirationDate的值来检查本地用户帐户的密码是否过期时。它在某些环境中失败,出现异常-在缓存中找不到目录属性。C# System.Runtime.InteropServices.COMException:在缓存中找不到目录属性,c#,visual-studio,C#,Visual Studio,当我们试图通过检索属性PasswordExpirationDate的值来检查本地用户帐户的密码是否过期时。它在某些环境中失败,出现异常-在缓存中找不到目录属性。 “An exception has occured and the exception is: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Run
“An exception has occured and the exception is:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: The directory property cannot be found in the cache”.
运行以下代码时
使用(var userEntry=new System.DirectoryServices.DirectoryEntry(“WinNT://“+domain+'/'+user+”,user”))
{
DateTime expiryDate=(DateTime)userEntry.InvokeGet(“PasswordExpirationDate”);
是否检查了从DirectoryEntry获取的userEntry对象,以获取PasswordExpirationDate?看起来像是错误的属性名称,它使用更直观的“pwdLastSet”查看其他代码;)脚本代码可能有助于查看角落案例。