views:

32

answers:

3

Hi,

I wrote a class library in C# that uses a external XML file to store some data. I use this data (encoded rules) directly in the class library to do some substitutions within a text parser. The rules within the XML:

 <rule>
   <word>h e l l o</word>
   <sub>Hello</sub>
 </rule>

When I share the lib, I also have to share the XML. This is a bug source, at least for me ;) My question: is there any common way to solve such issues? Should I use app.config instead?

Thanks for any hint and best regards!

+1  A: 

Why not embed the XML within the dll?

Preet Sangha
Yeap.. you could add it as a resource to the solution and in the properties select embedded.
jpsstavares
Because the xml could be changed by the user after deployment. New rules can be added or old ones needs to be removed.
A: 

Create the XML file with default settings/values if it doesn´t exist.

Jehof
This will help to avoid a FileNotFound exception, yes. I will validate the XML via XSD too.
A: 

As with every external configuration data i can be changed or missing. So your application (or library) has to deal with such circumstances.

This means:

  • For every missing value you have a default value (should be declared in your documentation)
  • Check every value for correctness (type, range, etc.) (All input is evil!)
  • Blame user for invalid config files (error message, etc)
  • Implement and document behaviour in error case (abort, crash, use default value, etc)

So it doesn't matter which way to go, cause it is a user configuration (which means it can be changed by the user) and so you have to check those entries.

Oliver
Ok, I will consider all these hints! I thought there are some common convetions I did'nt heard about.