-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Comments
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.
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.
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 ? |
Should we consider removing the exception from Version.ToString and using min(requestedNumber, actualNumber)? |
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. |
This issue will now be closed since it had been marked |
My Suggestion
Make
Environment.Version
returns a 4 fields instance ofVersion
such as3.100.320.12801
instead of 3 fields instance such as3.1.201
.Why I want the suggestion?
When we call
Version.ToString(fieldCount)
anArgumentException
might throw out if the Version has only 3 version fields. But we have no direct way to detect how many fields theVersion
instance has. If we want to avoid the exception, we can do one of these two things below:fieldCount
argument to pass into.ToString()
method directly instead of the one withfieldCount
overload.The first one causes a lot of checking codes everywhere and the second one limit the usage of the
Version
(onlyToString()
is allowed and it is still dangerous to pass the version instance to other modules.)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 fieldsVersion
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 kept4.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.
The text was updated successfully, but these errors were encountered: