One of the brilliant innovations when it comes to the .NET documentation is the ability to run (some) samples in your browser.

So, take the following case for the documentation of the DateTime.ToString() method.

If you scroll down, you will find not only some code samples, but there is a button to actually run them.

CodeSample

Unfortunately, this does not actually work!

CodeSampleNotWorking

I discovered by chance that you can modify the code, a nice touch.

The problem here is importing the appropriate namespace, System.Globalization.

So I fixed them directly in the sample.

A nice touch is that you get IntelliSense:

Intellisense

Unfortunately, this does not work either!

DoesNotRunEntryPoint

It is throwing an error about an inability to find an entry point.

I will spare you the grief of trial and error to get it to run.

You will need to add the following to the sample for it to run:

public class Program
{
  public static async Task Main(string[] args){
    //
    // Sample code is here
    //
  }
}


After which, success.

In Invariant Language (Invariant Country), 05/01/2025 09:00:00
In en-US, 5/1/2025 9:00:00 AM
In fr-FR, 01/05/2025 09:00:00
In de-DE, 01.05.2025 09:00:00
In es-ES, 1/5/2025 9:00:00
In ja-JP, 5/1/2025 09:00:00

Let us assume this problem manifested only in .NET 9, which was released on 12 November 2024.

One (or more of these is possible)

  1. It has never worked, and nobody has noticed
  2. It never worked; someone noticed, but nobody logged a report.
  3. It never worked; someone noticed, logged a bug report, and nobody read the report
  4. It worked; someone noticed, filed a bug report, somebody read the report, and did nothing
  5. It worked, and then at some point broke, at which point GOTO #1 and follow the logic

There is no reason to believe this problem is isolated to the DateTime samples.

I have logged it myself. Hopefully, it will be resolved soon.

TLDR

The runnable sample for DateTime.ToString does not run.

Happy hacking!