Interview Questions On Assemblies In .NET
Q: What is GAC (Global Assembly Cache)?
A: GAC
is a central repository folder where you can store and share your DLL among different
applications running in the same computer. So for example you have accounting
and invoicing application running in the same computer and both these
application need some common utility like the logging DLL then you need to
register them in GAC and share with them this dll from one common location instead of referencing the logging dll from logging project bin directory.
Q: If
we have different versions of DLL in GAC how can the application identify them?
A: This
is done by using binding redirect and specifying older version and new version
value. So which ever version you put in the new version will be used by the
application.
Q: What
are the various ways by which you can register a DLL in GAC?
A: There are several ways to do so
1. If Visual studio is installed on machine then you can use gacutil.exe that can be executed through visual studio command prompt. For example to register "MySample.dll" in GAC , you can use
gacutil \i MySample.dll
and your dll will be successfully registered in GAC.
2. If machine didn't have visual studio installed which is the case with servers mostly then we have to use some Window Installers to install the respective dll in GAC, for this simple create deployment project and then right click on file system and select GAC folders from the list and once it is done simply install the project, your respective dll will be installed in GAC folder.
Q: If
we do not have strong name can assembly be registered in GAC?
A: This
is again a catchy question which is testing do you know the pre-requisites to
register DLL in GAC. No, you cannot register DLL in GAC without strong names.
Q:How
do we create strong named DLL?
A: There are two ways to generate strong names for an assembly
1. By invoking sn.exe through visual studio command prompt i.e
sn -k MyStrong.snk
Where MyStrong.snk is the name of the file that will contain key/value pair for strong names and this file will be added in your current application.
2. You can also generate strong keyname also called signing your assembly through properties window of your application. Open property pages and then navigate to Signing Tab and there then check the "sign the assembly" checkbox and then there is a dop down box below this option then click on that box and simply select "new" and specify any name for the file and click add, then you will see that file with same name you specified with ".snk" extension is added in your current project and this is the strong keyfile name.
Q: Can we have assembly with same name but different versions in GAC?
A: Yes, we can have.
No comments:
Post a Comment