An error occurred in the Contacts module while using the Aspose.Email API

I am using the Aspose.Email API (licensed version).
I was retrieving the contact data, but it throws the exception: “Not a valid Win32 FileTime”.
They receive the contact data item-wise, so please add this as well.

@Anjali12

Summary
The “Not a valid Win32 FileTime” exception is thrown by Aspose.Email when a contact contains a DateTime value that cannot be represented as a Win32 FILETIME (the valid range is 01‑01‑1601 to 31‑12‑9999). The library validates these fields when a contact is materialised, and an out‑of‑range or corrupted value causes the exception.

Why it happens

  • Aspose.Email checks every DateTime property of a Contact (e.g., Birthday, Anniversary, CreationTime, LastModifiedTime, and any custom date properties).
  • If any of those properties holds a value such as 0001‑01‑01, a negative tick count, or a date beyond 31‑12‑9999, the value cannot be converted to a Win32 FILETIME and the SDK raises the exception.
  • This situation usually originates from a malformed source file (PST, OLM, MSG, etc.) that stores an invalid date.

What to do next

  1. Identify the problematic contact(s)
// .NET example
var client = new MailClient(...); // your mail store client
foreach (var contact in client.GetContacts())
{
try
{
// Access a date field to force full materialisation
var bday = contact.Birthday;
}
catch (Exception ex)
{
Console.WriteLine($"Contact Id={contact.Id} caused error: {ex.Message}");
}
}

The output will reveal which contact(s) trigger the exception.

  1. Examine the date‑time properties of the identified contact(s)
  • Birthday / Anniversary
  • CreationTime / LastModifiedTime
  • Any custom properties that store DateTime values (e.g., contact["MyDate"])

Verify that each value falls within 01‑01‑1601 – 31‑12‑9999. If you can edit the source file, correct or remove the out‑of‑range entries.

  1. Apply a defensive coding pattern
  • Wrap each date access in a try/catch block and skip the contact when the exception occurs.
  • Optionally log the contact identifier for later analysis.
  1. Consider a data‑sanitisation workflow
  • Export the contacts to a neutral format such as CSV or vCard.
  • Clean any invalid dates in the exported file (e.g., replace them with a valid placeholder or delete the column).
  • Re‑import the cleaned data using Aspose.Email.
  1. If the issue persists, gather diagnostic information
  • Exact Aspose.Email version you are using.
  • Minimal reproducible code snippet that triggers the exception.
  • Type of source file (PST, OLM, MSG, etc.) and, if possible, the identifier of the failing contact.

With this information we can forward the case to the product team for a deeper investigation.


We will review any additional details you provide and work with the internal development team to determine whether a library update or a more specific fix is required.

SDK version unclear — refer to the official release notes before applying this guidance.

bool ConvertOlmToPst(string olmFilePath, string fullPstPath)//last
{

    // Create a new PST
    PersonalStorage pst = PersonalStorage.Create(fullPstPath, FileFormatVersion.Unicode);
    var root = pst.RootFolder;

    FolderInfo inboxFolder = pst.CreatePredefinedFolder("Inbox", StandardIpmFolder.Inbox);
    ageDict.Add("Inbox", inboxFolder.ContainerClass);
    FolderInfo sent = pst.CreatePredefinedFolder("Sent Items", StandardIpmFolder.SentItems);
    ageDict.Add("Sent Items", sent.ContainerClass);
    FolderInfo drafts = pst.CreatePredefinedFolder("Drafts", StandardIpmFolder.Drafts);
    ageDict.Add("Drafts", drafts.ContainerClass);
    FolderInfo junk = pst.CreatePredefinedFolder("Junk Email", StandardIpmFolder.JunkEmail);
    ageDict.Add("Junk Email", junk.ContainerClass);
    FolderInfo calendar = root.AddSubFolder("Calendar", "IPF.Appointment");
    ageDict.Add("Calendar", calendar.ContainerClass);
    FolderInfo contacts = root.AddSubFolder("Contacts", "IPF.Contact");
    ageDict.Add("Contacts", contacts.ContainerClass);
    FolderInfo journal = root.AddSubFolder("Journal", "IPF.Journal");
    ageDict.Add("Journal", journal.ContainerClass);
    FolderInfo notes = pst.CreatePredefinedFolder("Notes", StandardIpmFolder.Notes);
    ageDict.Add("Notes", notes.ContainerClass);
    FolderInfo tasks = root.AddSubFolder("Tasks", "IPF.Task");
    ageDict.Add("Tasks", tasks.ContainerClass);
    //Add redifine folder Types//.............................//
    ageDict.Add("Address Book", "IPF.Contact");
    ageDict.Add("Suggested Contacts", "IPF.Contact");

    ageDict.Add("Junk E - mail", "IPF.Note");
    ageDict.Add("Outbox", "IPF.Note");
    ageDict.Add("Deleted Items", "IPF.Note");
    ageDict.Add("All", "IPF.Note");
    ageDict.Add("Follow-Up", "IPF.Note");
    ageDict.Add("Inbox-Categorized1", "IPF.Note");//Suggested Contacts
                                                  //--------------------------------------------------------//

    OlmStorage olm = new OlmStorage(olmFilePath);
    nTotalCount = GetOlmTotalItemCount(olm);
    //nTotalCount = GetTotalItems(olm);
    if (nTotalCount == 0)
    {
        Console.WriteLine("⚠️ No items found in OLM file.");
        return false;
    }

    List<OlmFolder> folders = GetAllOlmFolders(olmFilePath);       
    string Type;
    for (int i = 0; i < folders.Count; i++)
    {
        var folder = folders[i];           
        if (ageDict.TryGetValue(folder.Name, out Type))
        {
            Console.WriteLine($"Alice's age is {Type}");
        }            
        else
        {
            Type = DetectFolderType(olm,folder);
            if (string.IsNullOrEmpty(Type))
            {
                Type = "IPM.Note";
            }
        }          
        if (folder.Name != "Accounts")
        {
            FolderInfo folderfull = EnsureFolderPath(pst, folder.Path, Type);
            try
            {
                try
                {
                    // ✅ Enumerate messages safely
                    var messages = olm.EnumerateMessages(folder);
                    if (messages == null)
                        return false;

                    foreach (MapiMessage mapi in messages) // ✅ Correct type for v25.11
                    {
                        try
                        {
                            if (mapi == null)
                                continue;

                            // ✅ Handle calendar items safely
                            if (mapi.MessageClass.StartsWith("IPM.Appointment", StringComparison.OrdinalIgnoreCase))
                            {
                                var calItem = (MapiCalendar)mapi.ToMapiMessageItem();  // renamed variable

                                // Sanitize invalid dates
                                if (calItem.StartDate < new DateTime(1900, 1, 1))
                                    calItem.StartDate = DateTime.Now;

                                if (calItem.EndDate < new DateTime(1900, 1, 1) || calItem.EndDate < calItem.StartDate)
                                    calItem.EndDate = calItem.StartDate.AddHours(1);

                                folderfull.AddMapiMessageItem(calItem);
                            }
                            else if (mapi.MessageClass.StartsWith("IPM.Contact", StringComparison.OrdinalIgnoreCase))
                            {
                                var contactItem = (MapiContact)mapi.ToMapiMessageItem();                                   
                                try
                                {                                        
                                    folderfull.AddMapiMessageItem(contactItem);                                      
                                }
                                catch (Exception ex1)
                                {
                                   Console.WriteLine($"⚠️ Skipped message in folder {folder.Name}: {ex1.Message}");
                                }
                            }

                            else if (mapi.MessageClass.StartsWith("IPM.Task", StringComparison.OrdinalIgnoreCase))
                            {
                                var task = (MapiTask)mapi.ToMapiMessageItem();
                                folderfull.AddMapiMessageItem(task);
                            }
                            else if (mapi.MessageClass.StartsWith("IPM.StickyNote", StringComparison.OrdinalIgnoreCase))
                            {
                                var note = (MapiNote)mapi.ToMapiMessageItem();
                                folderfull.AddMapiMessageItem(note);
                            }
                            else if (mapi.MessageClass.StartsWith("IPM.Activity", StringComparison.OrdinalIgnoreCase))
                            {
                                var journalItem = (MapiJournal)mapi.ToMapiMessageItem();
                                folderfull.AddMapiMessageItem(journalItem);
                            }
                            else
                            {
                                folderfull.AddMessage(mapi);
                                                                
                            }

                            totalMessageCount++;
                            if (nTotalCount > 0)
                                progress.Progress = (int)((totalMessageCount * 100) / nTotalCount);

                            WriteProgress();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"⚠️ Skipped message in folder {folder.Name}: {ex.Message}");
                        }
                    }                        
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ConvertOstToPst Exception: " + ex.Message);
                    UpdateProgress("Error");
                }
               
            }

            catch (Exception ey)
            {
               Console.WriteLine("ConvertOstToPst Exception: " + ey.Message);
                
            }
            Console.WriteLine($"Folder {i}: {folder.Name}");
            Console.WriteLine($"Folder {i}: {folder.Path}");
        }
    }
    // ✅ Calculate final PST size
    if (File.Exists(fullPstPath))
    {
        FileInfo pstInfo = new FileInfo(fullPstPath);
        double sizeInMB = pstInfo.Length / (1024.0 * 1024.0);
        progress.Convertedpstsize = $"{sizeInMB:F2} MB";
       
    }
    else
    {
        progress.Convertedpstsize = "0.00 MB";
    }
    pst.Dispose();
    Console.WriteLine($" Conversion complete: {totalMessageCount} items processed.");
    
    Console.WriteLine($"Total folders found: {folders.Count}");      
    return true;
}

var bday = contact.Birthday;
Isn’t working
other method ??

@Anjali12,

If you’re getting an error, the contact contains an invalid/out-of-range date. That’s a data issue, not an Aspose issue.

Use a safe read:

DateTime? bday = null;
try { bday = contact.Birthday; } catch {}

There’s no “other method”, please fix the source data.