Skip to content

Environment.OSVersion will now return the correct value for the OS on Windows. #19684

@ericstj

Description

@ericstj

Environment.OSVersion will now return the correct value for the OS

Previously Environment.OSVersion would return a version that may be incorrect on Windows if an application war running under compatibility mode, as mentioned here.

Now Environment.OSVersion will return the correct value.

Version introduced

.NET 5.0

Old behavior

Environment.OSVersion would return a version that may be incorrect when an application was running under Windows compatibility mode.

New behavior

Environment.OSVersion returns the actual version of the operating system.

Reason for change

Most users of this API expect it to return the actual version of the operating system. Most .NET applications do not specify their supported version in their application manifest, and thus get the default from the dotnet host. As a result the compatibility shim rarely is meaningful for the application that is running and they will typically get the actual version, except in cases where windows releases a new version and an older dotnet host is still in use. We felt that returning the actual version was more inline with the expectation of the users of this API.

Recommended action

Review and test any code that you have that uses Environment.OSVersion to ensure it behaves as desired.

Category

  • Core .NET libraries

Affected APIs

Environment.OSVersion

dotnet/runtime#33643
dotnet/runtime#33651

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 5Work items for the .NET 5 releasebreaking-changeIndicates a .NET Core breaking change

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions