-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Version Used: Default version included with Visual Studio 2015 Update 3
Steps to Reproduce:
- Add a class within 2 different namespaces with the same name. For example, Test class in the namespace A and B.
- In another project, import at the project level both namespaces.
- Create a new class file in the new project and reference the class created in step 1. In the example, we use the Test class.
- You will receive an ambiguous reference error due to the Test class existing in both namespace A and B.
- Add the imports statement at the top of the class to import the desired namespace. For example, Imports A.
- Ambiguous reference error goes away, but now you receive the Unnecessary Imports warning. Accepting the action will return you to the ambiguous reference error.
Expected Behavior: Unnecessary imports should check imported namespaces at the project level for duplicate class declarations and then check to see if any of those classes are referenced in the code. If so, the warning should be dismissed as it is being used to qualify which namespace to use in reference to the ambiguously named classes.
Actual Behavior: The compiler determines that the import has already occurred at the project level and therefore deems the import unnecessary, regardless of whether it is being used to qualify one of the ambiguous class references.
This can be resolved by fully qualifying the name; however, this poses more problems in an active development situation if someone adds another duplicated class name in another namespace. It can also be resolved via aliases, but this requires an alias for each instance of one of the classes that is duplicated, which in our case, would be several per file. The Imports statement is the easiest solution which broadly classifies all references within the class file.