Skip to content

The current thread culture affects XAttribute value serialization. #45952

@dimarudnev

Description

@dimarudnev

On Linux/MAC, the 'MINUS SIGN' (U+2212)' symbol is used as NegativeSign when a number is converted to strings and the Swedish culture is applied. See #26778.
This leads to unexpected behavior of the XAttribute class's value property.
If you pass a negative float number as a value of XAttribute, it will be converted to a string with an invariant culture.

(new XAttribute("a", -123f)).Value // will have 'HYPHEN-MINUS' symbol

If you pass a negative integer number as a value of XAttribute, it will be converted to a string with current culture settings. In the case of Linux + Swedish culture, incorrect xml is produced.

(new XAttribute("a", -123)).Value // will have 'MINUS SIGN' symbol

Please see the sample project below.
Steps to reproduce:

  1. Extract files from dotnetcoredocker.zip to the empty folder.
  2. Run the docker command:
docker build -t xmlculture . && docker run -it xmlculture

Actual Result:

Integer:
−123
\u2212
Float:
-123
\u002d

the "minus sign" is different for integer and float attribute value types: \u2212(MINUS SIGN) for integer and \u002d(HYPHEN-MINUS) for float.
Expected Result:
the "minus sign" is the same for integer and float attribute value types: \u002d(HYPHEN-MINUS) for integer and \u002d(HYPHEN-MINUS) for float.

I think the issue may be related to this code:

internal static string GetStringValue(object value)

For float, double and decimal are converted to a string with an invariant culture, and an integer value is converted with the toString method without parameters.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions