Why does intellisense work with Using directive but not when specifing types withing the namespace?
I can add the statement using System.Configuration;
to my code using intellisense, but I can't get any intellisense when I access the type ConfigurationManager
.
Why does intellisense work when entering the using directive, but doesn't work when specifying a type from that nam开发者_Python百科espace?
using System.Configuration;
namespace TestDBMSConnection
{
class Program
{
static void Main(string[] args)
{
var dataProviderName = ConfigurationManager.AppSettings["provider"];
}
}
}
I can fix the issue by adding a reference to System.Configuration, but I don't understand why I don't need to do that for intellisense to work for the using directive.
Classes in a namespace are not required to be located in the same assembly.
Some classes in the System.Configuration namespace are located in System.dll (such as SettingsBase) while some other classes are located in System.Configuration.dll (such as ConfigurationManager).
IntelliSense can only suggest classes and namespaces in referenced assemblies. So if you have System.dll referenced but not System.Configuration.dll, IntelliSense can suggest the System.Configuration namespace and the System.Configuration classes located in System.dll, but not those located in System.Configuration.dll.
IntelliSense can also not know in which unreferenced assembly a certain class might be located. So you have to reference System.Configuration.dll manually before you can use it.
Because intellisense forusing
shows you the list of known namespaces. And System.Configuration
namespace is already referenced(Some of the classes in this namespace are in system.dll or mscorlib.dll), while the ConfigurationManager
class is in System.Configuration.dll which is not referenced, and thus intellisense does not know about it.
精彩评论