I have two different libraries, Testlib1 and Testlib2 in the same namespace, but I want them to use different app.config files.
Can I create one application with two different app.config files?
There is only one app.config and run-time. If you have assemblies with different app.config sections that are required, you need to transfer them to the main app.config file.
The app.config file is for the executing application (usually an EXE file or web under IIS), not an assembly. If you want to share settings across multiple applications, see the answer in Is there any way for an App.config file to reference another full config file? (.NET).
The .NET configuration system is scoped by AppDomain, each AppDomain having its own config file.
It is therefore possible to have one application using more than one config file, if the applicaton creates additional AppDomains beside the one it starts in (see NUnit for an example of such an application).
Designing and implementing a multiple-AppDomain application is not a trivial task, and if your only objective is separating the configuration of two libraries there are easier ways to do it (but not using multiple full config files).
Related
I have to consume a WCF Service. I have multiple layers in my project. I have one output project and other are library projects. All are dll projects except one output project. I would like to know the best place to place my service references. This is one serious architecture related concern that I want to understand.
The best thing that I found is that App.config or Web.config are placed in output projects. I should add service references in output project only because it is it generates bindings and other endpoint details in config file only. I will be required to copy paste all the things in output project only if place it in dll projects.
You need to copy the WCF configurations into the main web.config or app.config project. Whatever the executing program is. Referenced here: Cannot call WCF WebService from DLL
Or don't use configurations at all, do it programmatically like here: WCF Configuration without a config file
Please, can someone clarify to me a loading process? Say, you have app.config file for your UI executable. You add Enterprise Library config sources in that file. Each config source refers to another config file, say, one for logging dll, one for data storage dll and one for services dll. In each aux configs you write sections related to Enterprise Library application blocks and some core sections from .NET System.Configuration namespace (for example, connectionStrings).
Now, when configuration system initialized during UI startup, how this hierarchial configuration will be loaded?
As I understand, Enterprise Library will load it's own configuration sections, and will follow file name links and load external configuration files for each FileConfigurationSource. And after will load it's own configuration sections from each external file, mixing them all together.
What about core .NET sections? Will it be loaded also hierarchially by means of Enterprise Library, or I should use configSource attribute for this purpose?
I have a class library with a app.config file with 4 settings in it. Previously when I tried this (VS2008) as soon as I referenced the library I would not be able to access the config file/application would break, but for some reason it works now. I have referenced the library in 3 applications and I can still access the settings fine but the actual config file is missing.
Does the config file get compiled along with the library as soon as you reference it or what happens to it?
(working in vs2010)
It probably works because there are defaults in the generated Settings.Designer.cs file. The more important question would be: How can I change my settings?
And that would require copying or merging the relevant XML sections from the library app.config to that of the referencing application.
The config file is renamed; "app" is replaced by the name of your assembly. So if your app.config is associated with a program, say Foo.exe, then in your output folder (eg bin\debug) you should have a Foo.exe.config. If your app.config is associated with a class library, say Bar.dll, then in the output folder it will be Foo.dll.config.
I have a class library which needs some configuration to function. This class library is referenced by multiple applications (Multiple ASP.Net websites, and Windows Forms applications)
It is my understanding that it is possible to store the configuration in the library's app.config => myDll.dll.config file. See: Putting configuration information in a DLL, and C# Dll config file
My issue is that I don't want to manually handle copying the config file to the bin folder of every host assembly. Is there a mechanism in .Net to handle pairing of the dll to its config file so that the accompanying configuration is copiled along with the dll whereever it is distributed/referenced?
If the config is the same for all instances of your dll, then I'd add it as an embedded resource, so it's part of your dll and not a separate file at all.
TO do this, either add it as a file resource to your Resources.resx file, or just add the file directly to your Project and then set its compile type (in the Properties window) to Embedded Resource.
You can then use Assembly.GetExecutingAssembly.GetManifestResourceNames() to list the names of the resources in your dll, and Assembly.GetExecutingAssembly.GetManifestResourceStream() to get a stream to read the file's data from. I'd probably use a simple homebrew XML format for my data and then an XmlTextReader/XmlDocument to read it very easily back in.
You'l have to deploy this .dll into GAC and put there the config file, all apps will first search the GAC when loanding a reference. Here is how you can deploy the dll + config.
So I'm trying to use a .Net Assembly in my web services project. This assembly requires lots of settings in App.config. But my web service doesn't have an App.config, it has a web.config. It seems that it uses sections that an app.config would have that don't even exist for web projects. Is there any way I can make this assembly work? (make it read another config file maybe?)
You should be able to simply use the same configuration sections in the web.config file that exist in the app.config and it would work.
The way the configuration subsystem works means that it does not matter.