Skip to content

Replace strings with resources in Mono corelib #34056

Closed

Description

@danmoseley

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))

Activity

  1. added
    help wanted
    on Mar 25, 2020
  2. added
    untriaged
    on Mar 25, 2020
  3. danmoseley commented on Mar 25, 2020

    @danmoseley
    ContributorAuthor

    Also some are grandfathered in, as in coreclr. Eg., throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity); in StringBuilder is "requiredLength" forever presumably.

  4. am11 commented on Mar 25, 2020

    @am11
    Member

    With a slightly relaxed pattern, it also captures the cases where the first argument is nameof() followed by a hard-coded string:

    $ git grep "Exception.*\""  :/src/mono/netcore/System.Private.CoreLib/src/*.cs | wc -l
    
    443
  5. danmoseley commented on Mar 25, 2020

    @danmoseley
    ContributorAuthor

    @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.

  6. jkotas commented on Mar 25, 2020

    @jkotas
    Member

    StringBuilder is "requiredLength" forever presumably

    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.

  7. danmoseley commented on Mar 25, 2020

    @danmoseley
    ContributorAuthor

    If you do not recall this kind of change breaking things, lets do it.

  8. marek-safar commented on Mar 25, 2020

    @marek-safar
    Contributor

    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.

  9. stephentoub commented on Mar 25, 2020

    @stephentoub
    Member

    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.

  10. marek-safar commented on Mar 25, 2020

    @marek-safar
    Contributor

    Every other assembly as well as the coreclr corelib build uses resources, as does 95% of the mono corelib via shared sources.

    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).

  11. danmoseley commented on Mar 25, 2020

    @danmoseley
    ContributorAuthor

    @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.

  12. stephentoub commented on Mar 25, 2020

    @stephentoub
    Member

    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).

    Understood, and not disagreeing. That's why I said such work "would be in addition to rather than instead of" this.

  13. marek-safar commented on Mar 25, 2020

    @marek-safar
    Contributor

    @danmosemsft I am not against someone doing the work

  14. danmoseley commented on Mar 25, 2020

    @danmoseley
    ContributorAuthor

    @eerhardt @vitek-karas is it safe to assume that the linker work will include #34057 ?

  15. 12 remaining items

  16. tudoranghelina91 commented on Apr 21, 2022

    @tudoranghelina91
    Contributor

    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?

  17. danmoseley commented on Apr 21, 2022

    @danmoseley
    ContributorAuthor

    Hello, I'm not sure what you're referring to. Could you give me some links into the places in the code?

  18. tudoranghelina91 commented on Apr 21, 2022

    @tudoranghelina91
    Contributor

    <data name="Arg_ArgumentException" xml:space="preserve">

    <data name="ArgumentException_BadMethodImplBody" xml:space="preserve">

    <data name="Argument_WaitHandleNameTooLong" xml:space="preserve">

    What's the difference between the prefixes of these 3 lines? I am talking about the name attribute

  19. jkotas commented on Apr 21, 2022

    @jkotas
    Member

    Yes, we are not consistent in using prefixes for resource strings. Pick the one that makes the most sense to you.

  20. ghost added
    in-pr
    on Nov 14, 2022
  21. tudoranghelina91 commented on Nov 20, 2022

    @tudoranghelina91
    Contributor

    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?

  22. jkotas commented on Nov 20, 2022

    @jkotas
    Member

    it seems that two people have been working on the same item, despite the assignee...

    Sorry about that.

    I could merge the changes I did, but I think that might cause merge conflicts.

    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

  23. databunks commented on Nov 21, 2022

    @databunks

    it seems that two people have been working on the same item, despite the assignee...

    Sorry about that.

    I could merge the changes I did, but I think that might cause merge conflicts.

    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

    @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

  24. ghost removed
    in-pr
    on Mar 23, 2023
  25. ghost locked as resolved and limited conversation to collaborators on Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuehelp wanted

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions