C#.NET AccountExpirationDate Parameter name: fileTime ---> System.ArgumentOutOfRangeException: Not a valid Win32 FileTime.

So we've found a rather strange bug in .NET Framework from 3.5.1 to the latest version (4.6.2).

When using the System.DirectoryServices.AccountManagement library you may get the following error when reading the AccountExpirationDate of a principal.

Not a valid Win32 FileTime.
Parameter name: fileTime ---> System.ArgumentOutOfRangeException: Not a valid Win32 FileTime.
Parameter name: fileTime
   at System.DateTime.FromFileTimeUtc(Int64 fileTime)
   at System.DirectoryServices.AccountManagement.ADStoreCtx.DateTimeFromLdapConverter(dSPropertyCollection properties, String suggestedAdProperty, Principal p, String propertyName, Boolean useAcctExpLogic)
   at System.DirectoryServices.AccountManagement.ADStoreCtx.AcctExpirFromLdapConverter(dSPropertyCollection properties, String suggestedAdProperty, Principal p, String propertyName)
   at System.DirectoryServices.AccountManagement.ADStoreCtx.Load(Principal p, String principalPropertyName)
   at System.DirectoryServices.AccountManagement.Principal.HandleGet[T](T& currentValue, String name, LoadState& state)
   at System.DirectoryServices.AccountManagement.AuthenticablePrincipal.get_AccountExpirationDate()
 

This can occur when the account expires value is set to -1 as seen in ADSIEdit.msc.







 
 
 
The solution to this problem is to either correct these values (Never Expires should be 9223372036854775807) or read the accountExpires value directly using the underlying DirectoryEntry object and checking if it is set to -1.
 

 

Comments

Popular posts from this blog

Windows Server 2016, 2019, 2022, Windows 10 and Windows 11: Date and time "Some settings are managed by your organization".

TFTPD32 or TFTPD64 reports Bind error 10013 An attempt was made to access a socket in a way forbidden by its access permissions.

Enable function lock for F1-F12 on HP ZBook mobile workstations