Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Difference between Imports System.Configuration vs. Adding Reference with System.configuration.dll

Posted on 2006-10-25
6
Medium Priority
?
701 Views
Last Modified: 2010-04-24
Good Day,

I'm working with VB.NET 2005 and I was attempting to access the ConfigurationManager Class.  When I looked at the documentation, it says that the namespace needed is System.Configuration.

Beautiful.

But my code wouldn't compile and I couldn't figure out what I was doing wrong.

Someone suggested that I add the .DLL as a reference to my project and everything now works.

So my question is, What is the difference between the two?  I thought if I included the Imports System.Configuration namespace, that I would have access to allthe classes under the System.Configuration namespace.  If that's the case, why would I need the DLL?

I've only offered 50 points, so if the answer is detailed, I'll raise the point level.

coson
0
Comment
Question by:coson
6 Comments
 
LVL 13

Expert Comment

by:newyuppie
ID: 17806530
from what i understand, the namespaces reside on the dll's, or projects. If you import the System.Xml namespace, you will find that it also adds a reference to System.Xml dll, since they are not mutually exclusive but, au contraire, they are the same thing.
Namespaces on the imports statement do not add the reference per se, what they do is just to allow you to use the classes inside the dll without all the name like System.Xml.DoMethod1(), and just use DoMethod1() instead.
In cases where 2 methods are named the same in various dll's, you will still need to reference using the full name to avoid confusions.

hope it helps
NY
0
 
LVL 13

Accepted Solution

by:
newyuppie earned 200 total points
ID: 17806543
in summary, if you want to use classes that reside in a dll, you need to add a reference to it. if you want to call them up in your code without using the full name to call it, import the namespace.
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17806547
in that order.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 64

Expert Comment

by:Fernando Soto
ID: 17806620
From the Microsoft documentation

Assemblies include one or more namespaces. When you add a reference to an assembly, you can also add an Imports statement to a module that controls the visibility of that assembly's namespaces within the module. The Imports statement provides a scoping context that lets you use only the portion of the namespace necessary to supply a unique reference.

http://msdn2.microsoft.com/en-us/library/h9st4tss.aspx

Fernando
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17806624
Ok..
the difference is that the imports statement is used to shorten the length of code you type (i.e. the namespace name) let's say you are using regularexpressions... the classes are located at System.Text.RegularExpressions

so if you declare a variable of type regex
Dim aa As System.Text.RegularExpressions.Regex
and the options would be like this System.Text.RegularExpressions.RegexOptions

if you add imports System.Text.RegularExpressions
then it is shortened to
Dim aa As regex
and the options would be like this RegexOptions

but you must add the reference to the dll to be able to import the namespaces and access its internal types.
so imports is only to ease the work but the references are necessary to use the dlls...

you could see the default imports... if you click on the project menu then project propertied you'll find the default imports in the tree item imports of Common properties in the tree on the left
0
 

Expert Comment

by:pthomassr
ID: 20295672
I still don't get it.  I added the "Imports System.Configuration" statement at the top of the module, and coded "strDBLocation = ConfigurationManager.AppSettings("DBLocation")" and got "ConfigurationManager is not declared" as an error.  So... what are the EXACT statements for the Imports statements, and the EXACT code to reference the proper class and method to extract a value from the web.config file?  Apparently, there is no "ConfigurationManager" in System.Configuration, or I have no reference to it yet.  Do you have a code sample that shows how to get a dbconnection string in VB.Net 2005 that will syntax properly?  If there are other steps outside code, can I also get detail steps to perform them?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question