Microsoft Technologies,Sap-Modules,Java,IBM-MainFrames,Siebel,Testing,DataBase,PHP, Bpo,Callcenter and Freshers Interview Questions.
What is Assemblies?types of Assemblies?
How Can Assemblies Avoid DLL Hell?
Most assemblies are private. Hence, each client application refers assemblies from its own installation folder. So, even though there are multiple versions of the same assembly, they will not conflict with each other. Consider the following example:
When you create a private assembly, an assembly is installed in a subdirectory of the application, so even if two assemblies have the same name there is no problem because an application will always refer to its own assembly. Now, consider the case when you develop a shared assembly. In this case, it is important to know how assemblies are versioned. All assemblies have a version number in this form:
1.major.minor.build.revision
If you change the original assembly, the changed version will be considered compatible with the existing one if the major and minor versions of both the assemblies match. When the client application requests an assembly, the requested version number is matched against available versions and the version matching the major and minor version numbers and having the latest build and revision numbers are supplied.
How Do I Create Shared Assemblies?
The following steps are involved in creating shared assemblies:
1.Create your DLL/EXE source code.
2.Generate a unique assembly name using SN utility.
3.Sign your DLL/EXE with the private key by modifying the Assembly Info file.
4.Compile your DLL/EXE.
5.Place the resultant DLL/EXE in a global assembly cache by using the AL utility.
How Do I Create a Unique Assembly Name?
Microsoft now uses a public-private key pair to uniquely identify an assembly. These keys are generated by using a utility called SN.exe (SN stands for shared name). The most common syntax of it is:
1.sn -k mykeyfile.key
where k represents that you want to generate a key and the file name following is the file in which the keys will be stored.
How Do I Sign My DLL/EXE?
Before placing the assembly into a shared cache, you need to sign it by using the keys you just generated. You mention the signing information in a special file called AssemblyInfo. Open the file from VS.NET solution explorer and change it to include the following line:
1.[assembly:AssemblyKeyFile("file_path")]
Now, recompile the project and the assembly will be signed for you.
Note: You also can supply the key file information during a command line compilation via the /a.keyfile switch.
How Do I Place the Assembly in a Shared Cache?
Microsoft has provided a utility called AL.exe to actually place your assembly in shared cache:
1.AL /i:my_dll.dll
Now, the utility will place your DLL at the proper location.
Hands On...
Now that you understand the basics of assemblies, you can apply your knowledge by developing a simple shared assembly. In this example, you will create a C#.NET component called SampleGAC (GAC stands for Global Assembly Cache). You also will create a key file named sample.key. You will sign your component with this key file and place it in the Global Assembly Cache.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment