Mar 12 2008

Using the Global Assembly Cache

Category: Programmingavinashsing @ 8:37 am

Libraries which are regularly accessed by more than 1 website should be placed in the Global Assembly Cache (GAC) for improved efficiency.

Where is the GAC folder located in Windows?

C:\WINDOWS\assembly

Where is the gacutil.exe tool?

Framework 1.1 (Visual Studio 2003) : C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322

Framework 2.0 (Visual Studio 2005) : C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin

Framwork 3.5 (Visual Studio 2008) : C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin

How to add an assembly (dll file) to the GAC?

See : http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=106

How to reference an assembly which is already in the GAC in your projects?

If you have a dll which you have put in the GAC and want to reference it in your web projects, you can add the assembly in your web.config file - as simple as this! So what you need to do is the following:

1. If your dll is called, ClassLibraryTest.dll, register it in the GAC with the gacutil.exe

2. At the command prompt (cmd), type gacutil -lr ClassLibraryTest > C:\tempGACFile.txt

3. From the contents of tempGACFile.txt you will see “The Global Assembly Cache contains the following assemblies:”. You need the line after this phrase to continue.

4. Open your web.config and stick this in as follows:

 

20 <compilation>

21 <assemblies>

22 <add assembly=ClassLibraryTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ab75ca89730a76d7, processorArchitecture=MSIL/>

23 </assemblies>

24 </compilation>

5. Once this is done, your dll is already being referenced in your project. So all you have to do is use it in your pages.

 

11 // from the GAC

12 using ClassLibraryTest;

6. The rest you should know :)

If that does not work, then what you’ll need to do is create a copy of the dll on your drive and you will then have the option to browse to this dll to add a reference to this through Visual Studio. What will happen then is when you compile your application, the runtime will check whether you have this dll in your GAC and if you do then it will use the one from the GAC rather than the local copy which you have referenced in your project.

You can check that the dll from the GAC is the one which is being referenced rather than the local copy by looking at the bin folder for your project - you shouldn’t see the dll you are referencing in the bin!


Mar 11 2008

Dot Net Framework and C Sharp releases

Category: Programmingavinashsing @ 6:07 am

For the .NET Framework:

Version Version Number Release Date
1.0 1.0.3705.0 2002-01-05
1.1 1.1.4322.573 2003-04-01
2.0 2.0.50727.42 2005-11-07 (C# 2.0 Released)
3.0 3.0.4506.30 2006-11-06
3.5 3.5.21022.8 2007-11-19 (C# 3.0 Released)

What can you do with C# 3.0?

Have a read on these links:

David Hayden

Sahil Malik


Mar 07 2008

Difference between the IS and AS keyword is C Sharp

Category: Programmingavinashsing @ 4:26 am

1) The ‘is’ keyword returns a boolean value and is true if the object can be cast as the type.

if (p is BondPencil) return; // GET OUT OF HERE!

2) The ‘as’ keyword is similar to ‘is’ but ‘as’ returns a reference to the object if it can be cast or a null reference if it can not be cast.

if (null != p as BondPencil) return; // GET OUT OF HERE!

Taken from a post on Understanding Interfaces.