views:

345

answers:

2

I am relatively new to ASP.NET programming (but not programming in general), and I have been looking through a project that has been handed off to me. Within this project, there is a bin directory which contains a slew of various DLL files.

Then, in the web.conf file, inside the assemblies structure (within the XML), there is a slew of other assemblies being added.

I've done a search on both SO and through Google in general, and I am still struggling over what the difference is between the two. Is one way "better" than the other? Any clarification that can be provided would be most appreciated.

Thanks.

A: 

The bin directory is a copy of all the dll's that are built and referenced by your project. When the web application is running, it looks in the bin directory for the physical dll's it needs to execute the web application.

lomaxx
Your second paragraph has incorrect statements. The DLLs referenced by web.config are absolutely never copied into the bin directory - *ever*.
Eilon
A: 

There are several ways to reference assemblies (DLLs, usually) in an ASP.NET application:

  1. Add the DLL to your application's "bin" directory. This creates an implicit reference in every code file and ASPX file in your application to that DLL. This means that code inside an ASPX file or inside a CS file in App_Code can use the types in that DLL.

  2. Add a reference to the DLL in the <assemblies> section in web.config. See MSDN for details on the syntax. There are generally multiple web.config files that apply to a particular web application. The application itself can have several web.config files (for example, a web.config in a particular folder might add its own references). There is also a global web.config (or machine.config) that has references available to all ASP.NET applications on the computer.

  3. Use the <%@ Assembly Name="" %> directive in a particular ASPX (or ASCX or MASTER) file. See MSDN for details on the syntax.

The references in a given file in an ASP.NET application is a combination of the applicable items above.

The reason you have to reference assemblies is that ASPX files (much like CS and VB files themselves) eventually get compiled by either the C# or VB compiler. In order for those compilers to know what types you want to use they need to know which assemblies contain those types.

Eilon
JasCav
You'd choose #1 if the DLL does not have a strong name signature, in which case it *can't* be in the GAC because the GAC requires that the assembly is signed. You'd choose #2 if the DLL is installed in the GAC. Thus, it's not really a "choice" per se, but more of a decision matrix.
Eilon