This question was triggered by another issue I was just dealing with. There is a managed library, MyAssembly.dll
, targeting .NET 4.0. It has its own MyAssembly.dll.config
file with some <bindingRedirect>
instructions. I believe the .config
file was generated by either compliler or NuGet package manager, as I did not create it manually.
The thing is, the binding instructions are ignored when the DLL gets loaded by a client app (RegAsm.exe
in my case, but I also verified this with a simple console .NET app). I had to move them from the DLL's .config file into the client EXE app's .config file, to be picked up by .NET runtime and get correctly resolved.
The question: what is the purpose of a .config file for a managed library assembly (.DLL), at all? Does it anyhow participate in the process of loading of the library assembly?
Unfortunately, you can only have one app. config file per executable, so if you have DLL's linked into your application, they cannot have their own app. config files.
The reason dll. config exists at all is because VS doesn't distinguish between libraries and EXEs when it needs to generate config settings. Therefore if you happen to be inside a library and VS needs to generate a config entry it'll generate it in a dll. config but that file will never be used at runtime.
An application configuration file is an XML file used to control assembly binding. It can redirect an application from using one version of a side-by-side assembly to another version of the same assembly. This is called per-application configuration.
Class libraries can access configuration settings in the same way as executable apps, however, the configuration settings must exist in the client app's App. config file.
There is no "purpose". The consumer of the library can copy the settings out of the .dll.config into their own .exe.config or web.config.
The .dll.config file simply gives Visual Studio someplace to store configuration for the library.
Consider that, in general, a single library can be used by multiple callers, each with a different configuration. It actually doesn't make much sense, in general, for the library to dictate the settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With