Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of .config file for a .DLL library assembly?

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?

like image 286
avo Avatar asked Nov 22 '13 02:11

avo


People also ask

Can a DLL have app config file?

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.

Why DLL config is created?

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.

What is app config file?

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.

Can a class library have an app config file?

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.


1 Answers

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.

like image 97
John Saunders Avatar answered Oct 26 '22 21:10

John Saunders