When we give a reference of some dll in our project and build the project that referenced dll gets copied in the bin folder of our project, and when we run our project then CLR searches the referenced dll as follows :-
- CLR searches the GAC only if the referenced dll is strongly typed.
- If assembly is not found in GAC then CLR searches the location in app.config (or web.config) file.
- If dll is not specified in config also then CLR searches the dll in the bin folder of the application where dlls usually gets copied when we build our project.
- If dll is not found in bin folder then application crashes.
Since our dll gets copied into the bin folder in order to prevent that we will stop copying of dll by right clicking on the dll and changing its Property “Copy Local” to false.
So you will see that when you run the project you will not get the dll but your project will run fine because of its getting dll refrenced from GAC.
Note - It also improves the performance of your application because the unneccessary copying of dll will not be done while building your application.
Specifying Dll in app.config file ?
Now if you don’t want to install your dll in GAC then we can create a separate folder of Shared Assemblies in our project and give the reference of dll from that folder in our project. After that select CopyLocal property to False.
Now you need to add the reference path of that dll in our project in the Configuration node of app.config or web.config project.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ClassLibrary" culture="neutral" publicKeyToken="cded344e9c33e53f"/>
<codeBase version="1.0.0.0" href="FILE:\\C:\Projects\ClassLibrary.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>