开发者

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

开发者 https://www.devze.com 2023-03-15 21:04 出处:网络
I have a simple doubt: I have an external assembl开发者_开发问答y that I want to reference. I have an Asp.Net application. I want to use that assembly in my Asp.Net application.

I have a simple doubt: I have an external assembl开发者_开发问答y 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号