INI files vs Registry vs XML

  • Thread starter Thread starter Bob Kirkwood
  • Start date Start date
B

Bob Kirkwood

I believe the intent in .NET is that we store application
setup information in an XML file now instead of the
Registry or INI files. Is this correct?

Are there any tools, sample apps, or guidelines for how to
do this?
 
Yes. MS wanted applications to be less intrusive in the
O/S if possible in order to support the XCopy deployment
that makes .NET so easy to deploy. Using the registry
generally requires a setup file and therefor negates a
lot of reasons for using .NET in terms of deployment (and
this will continue to become more of a problem when
Whidbey and the ClickOnce technology are released).

In terms of actually using the configuration file, see
the ConfigurationSettings class in the Configuration
namespace in the MSDN documentation.

Jeff Levinson

Author of "Building Client/Server Applications with
VB.NET: An Example Driven Approach"
 
Hi Dave,

Yes you can write to it as a normal XML file, to a
certain entent. I've found that modifying the nodes
(attribute values, etc.) is generally fine, but it's not
always possible to create new nodes. So it's still
limited. I'm starting to write my own config file
reader/writer to get around that, but as you said, it'd
be really nice if the ConfigSettings class lets us to
write to .config files.

Regards,
Donald Xie
-----Original Message-----
The one thing that everyone seems to fail to mention when responding to
these kinds of messages is that, using the ConfigurationSettings with
the .config file is only half a solution. You can read from it. To have something
truely usable it would be nice to be able to write as well.
 
Yes, In .NET, it is recommended to use XML config file instead of registry
and INI file. Here is a sample:

HOW TO: Store and Retrieve Custom Information from an Application
Configuration File by Using Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q313405


Luke

"Microsoft Security Announcement: Have you installed the patch for
Microsoft Security Bulletin MS03-026?? If not Microsoft strongly advises
you to review the information at the following link regarding Microsoft
Security Bulletin MS03-026
http://www.microsoft.com/security/security_bulletins/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026."
 
I don't think that the config file story was completely thought out. What we
have is very good, but the designers need to ask more questions about how it
will be used.

1) config files are not writable: you can use the System.Xml classes to
write to it, but it is a pain, and it takes too long to perform. Also once
you have written to a config file the values will be ready _only_ when a new
application domain is created, which usually means you have to restart the
app. (Contrast this to the registry and INI files).

2) config files are per app, so anyone using the same app will have the same
settings, contrast this to the registry where entries are written to the
HKCU hive. You can use isolated storage to store your own private config
files, but you will have to write your own class to read this data and the
values will not be used automatically for framework classes that need config
data

3) config files are simple text files so you cannot apply an ACL for
individual items. Contrast this to the registry (or SQL Server) where an
entry can have an ACL so that certain accounts are refused access to a value
(and presumably to a feature of the app that uses the value).

4) reading and writing to the registry (and items in a database like SQL
Server) is automatically multi-user. Thus more than one thread can read
different values in the registry at the same time. If you want to write to
the config file you'll have to be careful to make sure that your API does
not lock out other threads reading another section of the file. To make sure
that other threads are not locked out for reads, the config API caches the
values it reads into a in-memory HashTable, one for each appdomain.

I would have preferred a database implementation rather than a XML DOM based
implementation. I see few advantages in editing the config file by hand. I
like the following features of the config file:

1) the values read from machine.config and app.config are combined with the
app settings taking precedence
2) framework code get their configuration when they are initialized, because
of (1) it means that a config file distributed with the app would supply the
settings and machine.config does not have to be touched.

Richard
 
Richard Grimes said:
I don't think that the config file story was completely thought out. What we
have is very good, but the designers need to ask more questions about how it
will be used.

1) config files are not writable: you can use the System.Xml classes to
write to it, but it is a pain, and it takes too long to perform. Also once
you have written to a config file the values will be ready _only_ when a new
application domain is created, which usually means you have to restart the
app. (Contrast this to the registry and INI files).

NOTE: This depends on the app type as ASP.NET will automatically recycle
when a new .config file is dropped.

I concur with the registry push over .config.


--
Gregory A. Beamer
MPV; MCP: +I, SE, SD, DBA

**********************************************************************
Think outside the box!
**********************************************************************
 
I don't think that the config file story was completely thought out.
1) config files are not writable:

The app config files are intended strictly for application-wide
settings which are by default not going to change frequently. Since
they reside with the app, a normal user won't have write permissions
there anyway - so there's no need to make that file writeable.
2) config files are per app, so anyone using the same app will have the same
settings, contrast this to the registry where entries are written to the
HKCU hive.

As I said before - the app config files are intended as APPLICATION
CONFIGURATION FILES - not user settings files! They are - by design -
*NOT* user-specific - never intended to be. If you need to store user
settings, use some persistence mechanism into the isolated storage
area (e.g. streaming out a config object, or creating a XML-based user
preferences config file yourself).

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Marc said:
The app config files are intended strictly for application-wide
settings which are by default not going to change frequently. Since
they reside with the app, a normal user won't have write permissions
there anyway - so there's no need to make that file writeable.

Well, yes, they are used essentially provided as a replacement for command
line switches, which, of course, do not have a concept of being writable.
However, the registry was used for many configuration things, and worked
very well for per user configuration items that could change.

Since Microsoft are discouraging people from using the registry, how should
we handle per user configuration items that could change? This is why I say
that it was not thought out well.
As I said before - the app config files are intended as APPLICATION
CONFIGURATION FILES - not user settings files! They are - by design -
*NOT* user-specific - never intended to be.

<sigh> I have said such things myself *many* times -just do a google search
on my name and config. I just don't agree with the features that have been
provided. Note that the poster was asking for a comparison between config,
registry and INI, and that is what I did.
If you need to store user
settings, use some persistence mechanism into the isolated storage
area (e.g. streaming out a config object, or creating a XML-based user
preferences config file yourself).

Oh I see: you have no option but to roll your own.

You say 'configuration files weren't intended to be user-specific and while
I agree that this is clearly the case I assert yet again that they *should*
have thought about these issues and taken them into account in the original
design. This is especially concerning since the mechanism that they are
trying to persuade us from using, has those very features.

Richard
 
You say 'configuration files weren't intended to be user-specific and while
I agree that this is clearly the case I assert yet again that they *should*
have thought about these issues and taken them into account in the original
design.

Yes, indeed - at least some form of "user-specific" or
"user-writeable" config files would have been nice. Then again -
they're really not that hard to do, plus there are tons of samples out
there already, so really, you can just pick one and use it, basically.

Also, if you have very complex and varied needs, you can always use
the Microsoft Configuration Management Application Block, right?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/cmab.asp

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top