Debugging future dates using Visual Studio 2019

Viewed 98

I have a situation where I need to debug a process that runs at a future date. This is existing legacy code that uses DateTime.Now (C#) & GETUTCDATE() (T-SQL) within its code in several places. We're having to change the date & time on Windows 10 to test how the code behaves with future dates.

We've tried preventing internet access but the application uses 3rd Party API's which require Internet access. We normally get about 1 hour of debugging time before Visual Studio 2019 checks for a stale license.

The big problem is that we're running into license issues with Visual Studio 2019 in the middle of debugging. We get booted out and have to start over. The process is lengthy and normally takes about an hour to get to a debugging position.

Does anyone know of a switch or command line parameter to temporarily allow us to modify the system date without shutting down Visual Studio 2019 due to stale license? Or any techniques that anyone has tried to debug.

Thank you in advance for your help.

2 Answers

This is too much for a comment.

What you could try is to install a useful debugging tool called Fiddler.

With Fiddler running, monitor your http traffic when Visual Studio is running to see which addresses it is contacting and communicating with. You should see something like this in Fidder's Inspectors tab

enter image description here

Once you've identified or suspect what it's doing, open your Windows host file (usually C:\Windows\System32\drivers\etc\hosts) in Notepad and add entries for each URL, eg

0.0.0.0 dc.services.visuastudio.com

to temporarily block it connecting to that particular site.

Remove, or comment out, when done.

You say it's legacy code, but hopefully you can change it.

One option would be to substitute all uses of DateTime.Now with DateTimeEx.Now, and add a class like:

public static class DateTimeEx
{
    public static TimeSpan Offset { get; set; }
    public static DateTime Now => DateTime.Now + Offset;
}

You can set the Offset to whatever value you like for testing purposes.

Related