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
name collision with type Index added to System namespace #28099
area-System.Runtimedesign-discussionOngoing discussion about design without consensusquestionAnswer questions and provide assistance, not an issue with source code or documentation.
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.)
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.
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.
area-System.Runtimedesign-discussionOngoing discussion about design without consensusquestionAnswer questions and provide assistance, not an issue with source code or documentation.
Activity
stephentoub commentedon Dec 6, 2018
cc: @terrajobst, @tarekgh
tarekgh commentedon Dec 6, 2018
@terrajobst is it possible our Index can be moved to a different namespace?
terrajobst commentedon Dec 7, 2018
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.jhudsoncedaron commentedon Dec 7, 2018
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.
terrajobst commentedon Dec 8, 2018
System.Runtime.CompilerServicesis meant for types that you basically never have to use yourself. WhileRangeandIndexhave 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. ForRangeandIndexthe language only provides syntax for values. That's why these types belong to theSystemnamespace IMHO.Can you explain what you mean by that?
danmoseley commentedon Dec 10, 2018
Can you either
Indexorusing Index = MyNamespace.Index;at the top of all your files?jhudsoncedaron commentedon Dec 10, 2018
Number 2 is probably going to work.
danmoseley commentedon Dec 11, 2018
Can we close then?
jhudsoncedaron commentedon Dec 11, 2018
@danmosemsft : It looks like we're going to try on the whole codebase tomorrow and see what happens.
terrajobst commentedon Dec 13, 2018
Can we close this now?