You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Replace strings with resources in Mono corelib #34056
In src\mono\netcore\System.Private.CoreLib the pattern Exception\s\(" has 340 hits. All these strings should instead come from src\libraries\System.Private.CoreLib\src\Resources\Strings.resx somewhere. In most cases there are already equivalent strings that can be determined by brief inspection of equivalent code in src\coreclr\src\System.Private.CoreLib or possibly src\libraries\System.Private.CoreLib.
Sometimes the strings need adjustment eg throw new ArgumentException ("type is not TypeBuilder but " + type.GetType (), "type"); vs throw new ArgumentException(SR.Argument_MustBeTypeBuilder);.
Some strings are in native code in coreclr eg throw new SynchronizationLockException ("Object is not synchronized"); is not thrown in Monitor.cs in coreclr. In this case it can just be throw new SynchronizationLockException()
A (very?) few may need new strings.
There are also a few trivial cases where the string should be replaced with nameof eg throw new ArgumentException("className") -> throw new ArgumentException(nameof(className))
Also some are grandfathered in, as in coreclr. Eg., throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity); in StringBuilder is "requiredLength" forever presumably.
I am not sure this is a step in right direction. We'll probably have to do work in the opposite direction and remove all resources overhead to cut on the size on workloads where English support is enough.
Every other assembly as well as the coreclr corelib build uses resources, as does 95% of the mono corelib via shared sources. Plus we want error messages to be the same across builds and not have to update them in many places when they change. I agree it'd be valid for the linker to optionally inline resource strings (or some other build step doing it), but that would be in addition to rather than instead of consistency in this last mile.
@marek-safar thanks for pointing this out. Would you have any reason for concern if your #34057 is completed? It seems like these strings would be a small issue in comparison so that work likely is inevitable.
Hey @danmoseley Sorry to bother you again. I am a bit confused regarding ArgumentExceptions. Which prefix to use? Argument or ArgumentException? is Argument prefix the same as ArgumentException prefix?
I know I haven't opened a PR on this one yet, but it seems that two people have been working on the same item, despite the assignee... I could merge the changes I did, but I think that might cause merge conflicts.
@tudoranghelina91 Sorry i assumed that the status of the project was idle as it had been since April,
if you have made any changes you feel should be added do tag me and we will just compare them,
here is the PR im tryna resolve: #78341
Activity
danmoseley commentedon Mar 25, 2020
Also some are grandfathered in, as in coreclr. Eg.,
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);in StringBuilder is "requiredLength" forever presumably.am11 commentedon Mar 25, 2020
With a slightly relaxed pattern, it also captures the cases where the first argument is
nameof()followed by a hard-coded string:danmoseley commentedon Mar 25, 2020
@am11 thanks.
I did a few -- I can put up a PR when the base change is in: stephentoub/runtime@enablemonoanalyzers...danmosemsft:dan.on.stephen
You are welcome to do more, if you like.
jkotas commentedon Mar 25, 2020
Is there a reason for it? We have fixed many similar bugs over the years, I do not see a reason why not to fix this one.
danmoseley commentedon Mar 25, 2020
If you do not recall this kind of change breaking things, lets do it.
marek-safar commentedon Mar 25, 2020
I am not sure this is a step in right direction. We'll probably have to do work in the opposite direction and remove all resources overhead to cut on the size on workloads where English support is enough.
stephentoub commentedon Mar 25, 2020
Every other assembly as well as the coreclr corelib build uses resources, as does 95% of the mono corelib via shared sources. Plus we want error messages to be the same across builds and not have to update them in many places when they change. I agree it'd be valid for the linker to optionally inline resource strings (or some other build step doing it), but that would be in addition to rather than instead of consistency in this last mile.
marek-safar commentedon Mar 25, 2020
I am aware of that and that would be unfortunate size regression if we had to ship with that (made tracking issue for that as #34057 a bit earlier).
danmoseley commentedon Mar 25, 2020
@marek-safar thanks for pointing this out. Would you have any reason for concern if your #34057 is completed? It seems like these strings would be a small issue in comparison so that work likely is inevitable.
stephentoub commentedon Mar 25, 2020
Understood, and not disagreeing. That's why I said such work "would be in addition to rather than instead of" this.
marek-safar commentedon Mar 25, 2020
@danmosemsft I am not against someone doing the work
danmoseley commentedon Mar 25, 2020
@eerhardt @vitek-karas is it safe to assume that the linker work will include #34057 ?
12 remaining items
tudoranghelina91 commentedon Apr 21, 2022
Hey @danmoseley Sorry to bother you again. I am a bit confused regarding ArgumentExceptions. Which prefix to use? Argument or ArgumentException? is Argument prefix the same as ArgumentException prefix?
danmoseley commentedon Apr 21, 2022
Hello, I'm not sure what you're referring to. Could you give me some links into the places in the code?
tudoranghelina91 commentedon Apr 21, 2022
runtime/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Line 190 in e09903f
runtime/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Line 1531 in e09903f
runtime/src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Line 1528 in e09903f
What's the difference between the prefixes of these 3 lines? I am talking about the name attribute
jkotas commentedon Apr 21, 2022
Yes, we are not consistent in using prefixes for resource strings. Pick the one that makes the most sense to you.
tudoranghelina91 commentedon Nov 20, 2022
I know I haven't opened a PR on this one yet, but it seems that two people have been working on the same item, despite the assignee... I could merge the changes I did, but I think that might cause merge conflicts.
Shall I unassign myself from this one and drop all the work @AaronRobinsonMSFT @danmoseley @jkotas?
jkotas commentedon Nov 20, 2022
Sorry about that.
For reference, would you mind sharing the branch with the changes that you have done?
You can also comment on the opened PR in case you see places that you have handled in your changes in a better way.
cc @databunks
databunks commentedon Nov 21, 2022
@tudoranghelina91 Sorry i assumed that the status of the project was idle as it had been since April,
if you have made any changes you feel should be added do tag me and we will just compare them,
here is the PR im tryna resolve: #78341
Replacing exception strings with those stored in the resx file
Replacing exception strings with those stored in the resx file (#79378)
Mono: Replace exception strings with those stored in the resx file (#…