1
votes

I have some third party assemblies installed in the GAC. I am developing an ASP.NET which uses some of these assemblies. In the development machine if an assembly is not in the bin folder it gets loaded from the GAC. This situation masks the situation if an assembly is missing in the bin folder because no errors are reported. However when the app is deployed on a shared host, if an assembly is missing from the bin folder, the app errors.

Is there a way to force the app not to load certain assemblies from the GAC and report an error if its missing in the bin folder in the development machine?

4

4 Answers

0
votes

You can't, as far as I know.

The answer to questions of the kind "Doctor, it hurts when I do this" is usually "Then don't do that".

In other words: Don't install the third party assemblies in the GAC on your development machine.

0
votes

For reason, I think you already know what the solution is. You should simply put these assemblies in the bin folder of your web app and then specify the assembly name in the required section of the web.config file. For example, if it is a server control that you want to register in all pages you add it in the pages section...

<pages styleSheetTheme="DefaultTheme" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
      <controls>
        <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" />
      </controls>
</pages>

if it is a custom module, you should specify in the modules section...

<httpModules>
      <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
    </httpModules>

You should always strive to set a development environment as close as possible to a production environment, which means third-party assemblies which are distributed with the .NET Framework should go in the bin...I mean, the bin folder, not the rubbish bin ;)

0
votes

NO, You cannot!. This is a fixed behavior by the CLR's Fusion engine.

The Fusion engine (responsible party for loading assemblies in .Net) ALWAYS walks it's steps (temp/download/gac/base path/probe paths) and you cannot prevent/change this.

if you have an assembly in two places, the one which is located first in the list mentioned above is loaded (can be very confusing with different versions).

0
votes

No, you can't. Locating assembly is a complex fallback algorithm.

  • Determine the required assembly name, version
  • IIf the required assembly is already loaded? If yes use it.
  • If not, whether it is in GAC? If yes use it.
  • If not, whether it is in the place where <codebase> or <probing> element says? If yes use it.(This is where startup path comes to place.)

As we see the runtime continues to search for assembly till it finds it(upto an extent). GAC comes in third place, It will be executed when step1 and 2 fails. There is no way to say don't look into GAC.

As a workaround: You can manually check the application startup path, If required assemblies are missing throw an "Exception" and terminate the process. Am not familiar with Asp.Net so not sure if that fits you.

Note:Above bullets are rough emphasis of mine, It is way more complicated than what I said above. For detailed information refer How the Runtime Locates Assemblies