Skip to content

NpgsqlRange.Parse use culture-specific parsing #3599

Closed

Description

@MaceWindu

Steps to reproduce

Execute following code while having non-dot decimal separator in current culture:

NpgsqlRange<decimal>.Parse("[1.1, null)")

The issue

I expect parse to work with invariant format for values but it is not the case.

 System.TypeInitializationException : The type initializer for 'NpgsqlRanges' threw an exception.
      ----> System.Exception : 1.1 is not a valid value for Decimal.
      ----> System.FormatException : Input string was not in a correct format.

Failing lines: https://github.com/npgsql/npgsql/blob/main/src/Npgsql/NpgsqlTypes/NpgsqlRange.cs#L432
I think it should call ConvertFromInvariantString instead of ConvertFromString

Also I see that #3168 removes Parse method, so probably this issue will be obsoleted.

Further technical details

Npgsql version: 4.1.8/5.0.3
Locale: nl-NL

Activity

  1. MaceWindu commented on Mar 14, 2021

    @MaceWindu
    ContributorAuthor

    Aww, tried to use culture-specific format and got Ranges with embedded commas are not currently supported. trying to parse 1,1 value. Which is expected, but makes Parse unusable

    https://github.com/npgsql/npgsql/blob/main/src/Npgsql/NpgsqlTypes/NpgsqlRange.cs#L410

  2. roji commented on Mar 15, 2021

    @roji
    Member

    I'd generally suggest avoiding Parse and using the constructors to construct the range you want; Npgsql generallz shouldn't be in the business of parsing string representations of arbitrary PostgreSQL types...

  3. roji commented on Mar 15, 2021

    @roji
    Member

    Am closing this as I don't think we should fix the Parse logic, but rather remove entirely as in #3168.

  4. added a commit that references this issue on Oct 7, 2025
    cf95ef4
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions