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?
Related
What is the purpose of *deps.json file in .NET Core?
What is the reason to store references in such file and not in assembly manifest(as in standalone .NET Framework)?
Using Ildasm i checked that assembly manifest doesn't contain entries for these dependecies after dotnet build command.
But it has entries after dotnet publish command.
The .deps.json file contains metadata about the assemblies referenced by the built assembly and the locations to search for them as well as information about the compilation options used.
This information is read by the native component (corehost) that loads and configures the runtime. When a referenced assembly needs to be loaded, the host will use the information in this file (as well as any runtimeconfig.json/runtimeconfig.dev.json) to locate the correct assembly to load.
This information is used in other places as well. For example ASP.NET Core's Razor view compilation also uses it to pass the correct references and configuration to the generated code. And unit test hosts also need to use the information in this file when a unit test library is loaded into the test host. The managed API to read and write this file is available in the Microsoft.Extensions.DependencyModel NuGet package.
Problem is that my settings from "app.config" is not being gotten in class library project.
Can "app.config" be used in applications only and not in class libraries?
You should add the config settings to the project that is using the class project. ie If you have a project 'MyProject' that references 'MyClassProject' then the app.config settings should be placed in the 'MyProject' project
Application configuration files contain settings specific to an application. This file contains configuration settings that the common language runtime reads (such as assembly binding policy, remoting objects, and so on), and settings that the application can read. The config file is optional, if it does not exist environments such as ASP.NET will fall back to the machine.config file stored in the .NET system directories to get machine wide defaults.
Think about it like that. If you class library has some custom settings then it should have a config to deal with it.
By design of .NET framework when you access Application configuration with default means - .NET runtime supplies you with data from app.config of entry assembly (an EXE file that references your class library).
Application Configuration of class library can be accessed in following way (code should be placed in project of class library - in order for Assembly.GetCallingAssembly().Location to return proper path):
ExeConfigurationFileMap classLibraryConfigurationMap= new ExeConfigurationFileMap();
classLibraryConfigurationMap.ExeConfigFilename = Assembly.GetCallingAssembly().Location + ".config";
Configuration classLibraryConfiguration = ConfigurationManager.OpenMappedExeConfiguration(classLibraryConfigurationMap, ConfigurationUserLevel.None);
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).
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.