Skip to content

SortVersion example code has a race condition #12017

@binki

Description

@binki

Type of issue

Other (describe below)

Description

The example suggests to check for a file’s existence and then attempt to open it. Instead, the code should attempt to open the file and act if the file doesn’t exist.

There’s another race condition in the SaveData() where partial data or an empty file can be created if the application is terminated while saving data. Ideally, the process would write the data to an alternatively-named file and then File.Replace() it.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.globalization.sortversion?view=net-9.0

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Globalization/SortVersion.xml

Document Version Independent Id

e2c8cee3-6e71-bc14-363f-783982c5de81

Platform Id

b384de06-3b2b-3198-4230-e969dbe15362

Article author

@dotnet-bot

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions