Wednesday, 12 April 2017

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.
 

 

No comments:

Post a Comment