System.DateTimeOnly icon indicating copy to clipboard operation
System.DateTimeOnly copied to clipboard

[BUG] Error CS0104 : `DateOnly` is an ambiguous reference between `System.Text.Json.DateOnly` and `System.DateOnly`

Open Swimburger opened this issue 10 months ago • 4 comments

Describe the bug

Because DateOnly is present on both the System and System.Text.Json namespace. Existing code needs to be de-conflicted by including the full namespace.

To Reproduce

using System.Text.Json;
using System;

namespace TestApp
{
    class Test
    {
        public DateOnly Date { get; set; }
    }

    internal static class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(JsonSerializer.Serialize(new Test()));
        }
    }
}

Expected behavior

DateOnly is only present on System.

Workaround

As a workaround, I'll copy the DateOnlyConverter code and not using the Portable.System.DateTimeOnly.Json package.

Swimburger avatar Feb 24 '25 18:02 Swimburger

Now I understand the problem completely, and I can confirm - it was a terrible idea to add a helper DateOnly (and TimeOnly) structs needed only for the code-generation scenarios into the widely used System.Text.Json namespace. It's not a big problem to move these types into a separate namespace, but because it's a breaking change, I should think about how I can help users who already depend on these types to simplify migration.

OlegRa avatar Mar 01 '25 11:03 OlegRa

@all-contributors please add @Swimburger for bug

OlegRa avatar Mar 01 '25 11:03 OlegRa

@OlegRa

I've put up a pull request to add @Swimburger! :tada:

allcontributors[bot] avatar Mar 01 '25 11:03 allcontributors[bot]

It's not a big problem to move these types into a separate namespace, but because it's a breaking change, I should think about how I can help users who already depend on these types to simplify migration.

That makes total sense. Thank you for the update.

Swimburger avatar Mar 02 '25 20:03 Swimburger