I have a project which needs to use NHibernate to communicate with my Oracle database.
Many projects at my workplace use NHibernate, so the NHibernate assembly was placed in the Global Assembly Cache, a tool that I do not entirely understand. From my research, I have gathered the following:
Point two obviously contradicts the other three, but if it were simply false, I wouldn't have any problems referencing libraries. It definitely reflects reality in that my GAC assemblies are nowhere to be found in the "Add References" window.
I would like to know two things:
and all .NET projects that reference it will now use the new version.
No, that's called DLL Hell. Applications reference a specific version of an assembly. You can update a DLL and update an application that uses it. And not break an old application that uses that DLL as well but didn't get recompiled. You can do that with the GAC because it can store multiple versions of a DLL. Or you can do this just as easily by keeping the DLL in the same directory as the application's EXE.
Assemblies in the GAC do not appear in the Add Reference dialog. Necessarily so, you don't know what your user has stored in her GAC. You use the Browse tab on your dev machine instead so you'll be sure that you use a specific build of the DLL.
The GAC is important to companies that need to distribute security updates. Like Microsoft. It ensures that there are no unpatched copies of the DLL floating around. Also important for [ComVisible] assemblies to solve COM's DLL Hell problem. That's about it.
A "brute force" method of adding a GAC reference in your project is to directly edit the project file. Unload the project and add a Reference
under the same ItemGroup
element as the other references in your project, for instance:
<Reference Include="System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
You need to be aware that there is a difference between the design-time location of assemblies in the .NET tab of the "Add Reference" dialog and the runtime resolution of those references to assemblies in the GAC. The difference between adding a reference via the .NET tab and the file browse tab is that the reference in the former case isn't marked as "Copy Local" and therefore at runtime will be looked up from the GAC. Microsoft typically places a copy of assemblies intended to be referenced from the GAC in folders under the %programfiles%\Reference Assemblies directory but these are only used at design-time.
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