Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Environment.Version returns 4 fields instead of 3 fields to avoid exception handling. #35564

Closed
walterlv opened this issue Apr 28, 2020 · 4 comments
Labels
area-System.Runtime design-discussion Ongoing discussion about design without consensus enhancement Product code improvement that does NOT require public API changes/additions

Comments

@walterlv
Copy link

My Suggestion

Make Environment.Version returns a 4 fields instance of Version such as 3.100.320.12801 instead of 3 fields instance such as 3.1.201.

Why I want the suggestion?

When we call Version.ToString(fieldCount) an ArgumentException might throw out if the Version has only 3 version fields. But we have no direct way to detect how many fields the Version instance has. If we want to avoid the exception, we can do one of these two things below:

  1. Check every field value and determine the fieldCount argument to pass into.
  2. Call ToString() method directly instead of the one with fieldCount overload.

The first one causes a lot of checking codes everywhere and the second one limit the usage of the Version(only ToString() is allowed and it is still dangerous to pass the version instance to other modules.)

System.ArgumentException: Argument must be between 0 and 3. (Parameter 'fieldCount')

https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/Version.cs#L261-L267

The history of this change

In .NET Framework, the Environment.Version always returned a 4 fields Version instance so many codes may worked well and maybe another module far away had tried to format the version to a special string. And after the .NET Core was invented, the value of this property kept 4.0.30319.42000 unchanged.

After this issue (#3271) and the pull request (c8809dc#diff-73f2844915c581aab917cddd369adec4L132-L135) this property started to return a 3 fields value.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Runtime untriaged New issue has not been triaged by the area owner labels Apr 28, 2020
@jkotas
Copy link
Member

jkotas commented Apr 28, 2020

We have done this to use the same .NET runtime version number everywhere. If we were to change this to return 4 part version, we would be again on path to have diverging runtime version number schemes in different parts.

3.100.320.12801

This number is .NET SDK version. It would not appropriate to use for .NET runtime version. It is not even possible - this version number is not available in .NET runtime.

The first one causes a lot of checking codes everywhere

If your project is sensitive to have versions with all 4 components, is it an option to add a wrapper that centralizes this check and fills in the 4th component ?

@stephentoub
Copy link
Member

Should we consider removing the exception from Version.ToString and using min(requestedNumber, actualNumber)?

@joperezr joperezr added enhancement Product code improvement that does NOT require public API changes/additions design-discussion Ongoing discussion about design without consensus and removed untriaged New issue has not been triaged by the area owner labels Jul 7, 2020
@joperezr joperezr added this to the Future milestone Jul 7, 2020
Copy link
Contributor

Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

This process is part of our issue cleanup automation.

@dotnet-policy-service dotnet-policy-service bot added backlog-cleanup-candidate An inactive issue that has been marked for automated closure. no-recent-activity labels Jan 7, 2025
Copy link
Contributor

This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@dotnet-policy-service dotnet-policy-service bot removed this from the Future milestone Jan 21, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Feb 20, 2025
@dotnet-policy-service dotnet-policy-service bot removed no-recent-activity backlog-cleanup-candidate An inactive issue that has been marked for automated closure. labels Feb 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime design-discussion Ongoing discussion about design without consensus enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

No branches or pull requests

5 participants