Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding ASP.NET assembly reference management in Web.config file

I have a simple doubt: I have an external assembly that I want to reference. I have an Asp.Net application. I want to use that assembly in my Asp.Net application.

I add a reference and what VS does is just placing my dll in the Bin subdirectory of my web site.

I thought that VS would have modified my web.config file adding external references... So does it happen only when referencing assemblies in GAC??? (which makes sense given that public tokens and versions are required).

Thankyou

like image 925
Andry Avatar asked Jun 28 '11 21:06

Andry


People also ask

What is assemblies explain why assemblies are used in .NET framework?

Assemblies are the fundamental units of deployment, version control, reuse, activation scoping, and security permissions for . NET-based applications. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality.

What is the use of web config file in asp net?

web. config file is an XML-based configuration file used in ASP. NET-based applications to manage various settings that are concerned with the configuration of our website. In this way, we can separate our application logic from configuration logic.

What is .NET assembly explain its types?

In the Microsoft . NET framework, an assembly is a partially compiled code library for use in deployment, versioning and security. There are two types: process assemblies (EXE) and library assemblies (DLL). A process assembly represents a process which will use classes defined in library assemblies. .


1 Answers

When the CLR loads your assembly for execution, it checks the assembly's manifest to determine what dependencies are required for it to run. It goes through a series of steps to do this:

  1. Check for redirects - if the assembly is strongly-named, the CLR will first check the appropriate config (app.config, web.config, etc.) to see if there are any binding redirects specified. A binding redirect allows the CLR to say, where I am supposed to load v1.0.0.0, instead load v2.0.0.0. If no binding redirect is found for a strongly-named assembly, it will check a policy file in the GAC, and if no policy file is found, it checks the machine.config. If no binding redirect is specified, the CLR will use the assembly name specified in the calling assembly's manifest to load the assembly.

  2. Check to see if the assembly has already been loaded - the CLR determines if the assembly has previously been loaded, if it has, it uses that same loaded assembly, otherwise it continues...

  3. Load the assembly from the GAC - If the assembly could not previously be loaded and is strongly-named, the CLR will attempt to load the assembly from the Global Assembly Cache.

  4. CodeBase - If the CLR still can't find the assembly, it will use the codeBase path to try and locate the assembly.

  5. Probing - If the CLR still can't find the assembly, it will check the probing path for the assembly. The default probing path is the application base path of the AppDomain into which assemblies are currently being loaded.

(That's all adapted from a great article called Understanding .Net Assemblies and References ).

In the case of your web application, the CLR still does all of the above, but the AppDomain application base path is the /bin folder within your IIS application.

like image 138
Matthew Abbott Avatar answered Oct 11 '22 23:10

Matthew Abbott