Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 513 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C# DLL config file

#1
Im trying to add an app.config file to my DLL, but all attempts have failed.

According to MusicGenesis in '[Putting configuration information in a DLL][1]' this should not be a problem. So obviously I'm doing something wrong...


[1]:

[To see links please register here]


The following code should return my ConnectionString from my DLL:

return ConfigurationManager.AppSettings["ConnectionString"];

However, when I copy the app.config file to my console application, it works fine.

Any ideas?



Reply

#2
ConfigurationManager.AppSettings returns the settings defined for the application, not for the specific DLL, you can access them but it's the application settings that will be returned.

If you're using you dll from another application then the ConnectionString shall be in the app.settings of the application.
Reply

#3
As Marc says, this is not possible (although Visual Studio allows you to add an application configuration file in a class library project).

You might want to check out the [AssemblySettings][1] class which seems to make assembly config files possible.


[1]:

[To see links please register here]

Reply

#4
if you want to read settings from the DLL's config file but not from the the root applications web.config or app.config use below code to read configuration in the dll.

var appConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
string dllConfigData = appConfig.AppSettings.Settings["dllConfigData"].Value;

Reply

#5
I know this is late to the party, however I thought I would share the solution I use for DLL's.

I am more of the K.I.S.S. school of thinking, so when I have a .NET DLL that wants to store external data points that control how it works or where it goes, etc. I simply create a "config" class that has only public properties that store all the data points it needs and that I would like to be able to have controlled external to the DLL to prevent recompiling it to make the changes. Then I use .Net's XML Serializing to save and load the object representation of the class to a file.

There are a lot of ways then to handle reading it and accessing it, from a Singleton, a static utility class, to extension methods, etc. This depends on how your DLL is structured and what method will fit your DLL best.
Reply

#6
When using ConfigurationManager, I'm pretty sure it is loading the process/`AppDomain` configuration file (app.config / web.config). If you want to load a specific config file, you'll have to specifically ask for that file by name...

You could try:

var config = ConfigurationManager.OpenExeConfiguration("foo.dll");
config.ConnectionStrings. [etc]
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through