Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

dll not reading .config ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Søren M. Olesen - 31 Mar 2006 11:46 GMT
Hi

I've created a Class library (myClasses.dll), and added a settings.settings
to it using designer.

However when I use this class library, it doesn't seem to read the settings
myClasses.dll.config file, instead I just get then initial values I used
when creating the settings.settings section.

What do I have to do to get the classlibrary to read the associated .config
file???

TIA

Søren
Phill  W. - 31 Mar 2006 12:55 GMT
> However when I use this class library, it doesn't seem to read the
> settings myClasses.dll.config file, instead I just get then initial values
> I used when creating the settings.settings section.

I've only ever seen these values read from an Application.EXE.config
which, annoyingly, means you have to ship these settings in every
application that uses your library.

Or, in a web application, (I think) these settings are read from the
web.config file.

HTH,
   Phill  W.
Brian Gideon - 31 Mar 2006 16:36 GMT
Phill,

I don't really see that as a problem in most situations.  When you add
a reference to the assembly you should also add the appropriate
settings to the app.config at that time.  In other words, you add them
at compile and not deployment time.  Furthermore, even if the
configuration infrastructure supported the *.dll.config method you'd
still have to deploy that file to every machine, but now you have more
than one file to keep track of.

Brian

> I've only ever seen these values read from an Application.EXE.config
> which, annoyingly, means you have to ship these settings in every
[quoted text clipped - 5 lines]
> HTH,
>     Phill  W.
Claes Bergefall - 31 Mar 2006 16:43 GMT
I just recently needed this functionality so here's the class I made to
accomplish it:

Imports System.Collections.Specialized
Imports System.Reflection.Assembly

Public Class AssemblyConfigurationSettings
   Public Shared ReadOnly Property AppSettings() As NameValueCollection
       Get
           Dim filename As String = GetCallingAssembly.Location & ".config"
           Dim settings As New NameValueCollection
           If Not System.IO.File.Exists(filename) Then
               Return settings
           End If

           Try
               Dim reader As New System.Xml.XmlTextReader(filename)
               Dim doc As New System.Xml.XmlDocument
               doc.Load(reader)

               Dim configurationNode As System.Xml.XmlNode =
doc.SelectSingleNode("configuration")
               If configurationNode Is Nothing Then
                   Return settings
               End If

               Dim appSettingsNode As System.Xml.XmlNode =
configurationNode.SelectSingleNode("appSettings")
               If appSettingsNode Is Nothing Then
                   Return settings
               End If

               Dim nodes As System.Xml.XmlNodeList =
appSettingsNode.SelectNodes("add")
               For Each node As System.Xml.XmlNode In nodes
                   settings.Add(node.Attributes("key").Value,
node.Attributes("value").Value)
               Next
           Catch ex As System.Xml.XmlException
           End Try

           Return settings
       End Get
   End Property
End Class

  /claes

>> However when I use this class library, it doesn't seem to read the
>> settings myClasses.dll.config file, instead I just get then initial
[quoted text clipped - 9 lines]
> HTH,
>    Phill  W.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.