Skip to content

name collision with type Index added to System namespace #28099

Closed

Description

@jhudsoncedaron

tag:discussion

We have this very old class that's used all over the place called Index, which is basically a Dictionary that accepts more than one item per key. It's used like a mutable IGrouping and was recently retrofitted to implement IGrouping. It's use is so pervasive that it grew another implementation called SortedIndex which is to Index as SortedDictionary is to Dictionary.

So now we've got literally thousands of files importing System and expecting Index to be ours (in a far namespace), and on upgrading to .NET Core 3 we get a completely ridiculous number of errors.

So now we've got to figure out how to handle this name collision. Trying to rename Index is going to break back-compatibility of our nuget packages all over the place.

(Yes, some parts of our .NET Core codebase are literally 11 years old and I've got the source control trees to prove 9 of them and would have more but for a disk crash.)

Activity

  1. stephentoub commented on Dec 6, 2018

    @stephentoub
    Member
  2. tarekgh commented on Dec 6, 2018

    @tarekgh
    Member

    @terrajobst is it possible our Index can be moved to a different namespace?

  3. terrajobst commented on Dec 7, 2018

    @terrajobst
    Contributor

    We could consider moving it but I don't think this will solve the OPs problem because it likely will be another core namespace that's imported by default. The only option I see is us renaming the type, but I think that would be substantially worse for everyone else.

    Historically, us trying to avoid naming collisions with consuming code is basically an exercise in futility unless we put new types in esoteric namespaces or choose multi-word names that are unlikely to collide, so for new core features (such as Task, Tuple, Range, Span) this simply isn't actionable for us.

  4. jhudsoncedaron commented on Dec 7, 2018

    @jhudsoncedaron
    Author

    In this case it has its own syntax, so System.Runtime.CompilerServices could be used.

    But I said discussion for a reason. Perhaps there's a good way to prioritize imports that can be mechanically applied at the file level.

  5. terrajobst commented on Dec 8, 2018

    @terrajobst
    Contributor

    In this case it has its own syntax, so System.Runtime.CompilerServices could be used.

    System.Runtime.CompilerServices is meant for types that you basically never have to use yourself. While Range and Index have language syntax, you still need to use the type name for parameters and return declarations of methods -- they are not like tuples where the language offered syntax for the type. For Range and Index the language only provides syntax for values. That's why these types belong to the System namespace IMHO.

    Perhaps there's a good way to prioritize imports that can be mechanically applied at the file level.

    Can you explain what you mean by that?

  6. danmoseley commented on Dec 10, 2018

    @danmoseley
    Contributor

    Can you either

    1. search and replace (or use Roslyn analyzer) to fully qualify use of your Index or
    2. insert statement like using Index = MyNamespace.Index; at the top of all your files?
  7. jhudsoncedaron commented on Dec 10, 2018

    @jhudsoncedaron
    Author

    Number 2 is probably going to work.

  8. danmoseley commented on Dec 11, 2018

    @danmoseley
    Contributor

    Can we close then?

  9. jhudsoncedaron commented on Dec 11, 2018

    @jhudsoncedaron
    Author

    @danmosemsft : It looks like we're going to try on the whole codebase tomorrow and see what happens.

  10. terrajobst commented on Dec 13, 2018

    @terrajobst
    Contributor

    Can we close this now?

  11. transferred this issue fromdotnet/corefxon Feb 1, 2020
  12. added this to the 3.0 milestone on Feb 1, 2020
  13. ghost locked as resolved and limited conversation to collaborators on Dec 14, 2020
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

    area-System.Runtimedesign-discussionquestion

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions