Skip to content

Custom Serializer ODataProperty DateTime ODataPrimitiveValue can only wrap values which can be represented as primitive EDM types.' #1945

Closed

Description

@rossbuggins

When implementing a custom serializer I'm getting the below exception when a DateTime object is added to ODataProperty. DateTimeOffset is fine. Looking at Microsoft.Odata.Core, there are some ifs around DateTime but not DateTimeOffset, lines 104 and 115 at https://github.com/OData/odata.net/blob/master/src/Microsoft.OData.Core/Metadata/EdmLibraryExtensions.cs

Whats the reason behind this?

Assemblies affected

Odata 7.2.2

Reproduce steps

var dateTime = DateTime.Now;
new ODataProperty() { Name = "UtcStart", Value = dateTime}

Expected result

Accept DateTime as a valid object, like DateTimeOffset is:

var dateTime = DateTime.Now;
new ODataProperty() { Name = "UtcStart", Value = new DateTimeOffset(dateTime, TimeSpan.Zero) }

Actual result

Microsoft.OData.ODataException: 'An ODataPrimitiveValue was instantiated with a value of type 'System.DateTime'. ODataPrimitiveValue can only wrap values which can be represented as primitive EDM types.'

Additional detail

Optional, details of the root cause if known. Delete this section if you have no additional details to add.

Activity

  1. xuzhg commented on Nov 6, 2019

    @xuzhg
    Contributor

    @rossbuggins DateTime is removed from OData built-in primitive type. Can you change to use "DateTimeOffset"?

  2. linked a pull request that will close this issuegroup by on date throws exceptions #2302on Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions