Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET assembly loading priorities

I have a solution with 3 projects (GUI, BL and DAL). The DAL assembly is signed and deployed in the GAC.

When I build the solution the DAL is compiled and the assembly placed in the bin folder of the main project. But when I run the application, it loads the GAC version instead of the local one. Why is this?

I realized that because the version in the GAC was not the latest one and some methods were missing, although it compiled fine.

Does the GAC have priority over the local bin folder?

Tks in advance

like image 729
Dante Avatar asked Oct 22 '09 10:10

Dante


1 Answers

Short answer Yes, the GAC has precedence over local files.
this is a different behavior from what we are used to in native dll world (excluding some system dlls that where always loaded from SYSTEM32 no matter what).

Why?
Imagine that you have multiple applications with the same assembly now that assembly has a bug how do you fix all of your applications? It hard to start search for all the applications on all drivers, its easier to deploy a single assembly to the GAC ans fix all the application at once.

As for your problem, if you change API you need to change the assembly version of that assembly, this way the fusion engine will pick up the version that is in the local folder.

like image 111
Shay Erlichmen Avatar answered Sep 27 '22 19:09

Shay Erlichmen