AFDatabase.ModifyDate Bug?

I am having an issue where the AFDatabase.ModifyDate value is set to an incorrect time after executing AFDatabase.Refresh(). Prior to the Refresh(), the correct modified timestamp is returned.

 

Here's an output demonstrating this issue:

Attempting to connect...

Successfully connected to MyServer.
Database: MyDatabase

-------------------------------------------------
  -  Database Modify Date (UTC): 2025-07-17 20:04:35
  -  Current Execution Time (UTC): 2025-07-17 22:55:22
-------------------------------------------------
[RESULT] The ModifyDate appears correct (the bug is NOT present).

-------------------------------------------------
  -  Database Modify Date (UTC): 2025-07-17 22:55:12
  -  Current Execution Time (UTC): 2025-07-17 22:55:22
-------------------------------------------------
[RESULT] The ModifyDate appears to be the current time (the bug is present).

Press any key to exit.

Here's the code:

using System;
using OSIsoft.AF;

namespace ConsoleApp13
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Attempting to connect...");

            try
            {
                string afServerName = "MyServer";
                string afDatabaseName = "MyDb";

                PISystems systems = new PISystems();
                PISystem afServer = systems[afServerName];
                AFDatabase afDatabase = afServer.Databases[afDatabaseName];

                DateTime modifyDate = afDatabase.ModifyDate.UtcTime;
                DateTime currentTime = DateTime.UtcNow;

                Console.WriteLine($"\nSuccessfully connected to {afServerName}.");
                Console.WriteLine($"Database: {afDatabaseName}");

                Console.WriteLine("\n-------------------------------------------------");
                Console.WriteLine($"  -  Database Modify Date (UTC): {modifyDate:yyyy-MM-dd HH:mm:ss}");
                Console.WriteLine($"  -  Current Execution Time (UTC): {currentTime:yyyy-MM-dd HH:mm:ss}");
                Console.WriteLine("-------------------------------------------------");


                if (modifyDate.Date == currentTime.Date && modifyDate.Hour == currentTime.Hour && modifyDate.Minute == currentTime.Minute)
                {
                    Console.WriteLine("[RESULT] The ModifyDate appears to be the current time (the bug is present).");
                }
                else
                {
                    Console.WriteLine("[RESULT] The ModifyDate appears correct (the bug is NOT present).");
                }

                afDatabase.Refresh();
                modifyDate = afDatabase.ModifyDate.UtcTime;

                Console.WriteLine("\n-------------------------------------------------");
                Console.WriteLine($"  -  Database Modify Date (UTC): {modifyDate:yyyy-MM-dd HH:mm:ss}");
                Console.WriteLine($"  -  Current Execution Time (UTC): {currentTime:yyyy-MM-dd HH:mm:ss}");
                Console.WriteLine("-------------------------------------------------");

                if (modifyDate.Date == currentTime.Date && modifyDate.Hour == currentTime.Hour && modifyDate.Minute == currentTime.Minute)
                {
                    Console.WriteLine("[RESULT] The ModifyDate appears to be the current time (the bug is present).");
                }
                else
                {
                    Console.WriteLine("[RESULT] The ModifyDate appears correct (the bug is NOT present).");
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine($"\nAn error occurred: {ex.Message}");
            }

            Console.WriteLine("\nPress any key to exit.");
            Console.ReadKey();
        }
    }
}

Can anyone reproduce this issue? I am using OSIsoft.AFSDK v3.1.0.1156.

Parents Reply Children
No Data