Index

ASSEMBLY tagged Questions - Page 1

.Net Assembly Interview Questions and Answers


What is an Assembly in .NET?
- Assembly is unit of deployment like EXE or a DLL.
- An assembly consists of one or more files (dlls, exe’s, html files etc.), and represents a group of resources, type definitions, and implementations of those types. An assembly may also contain references to other assemblies. These resources, types and references are described in a block of data called a manifest. The manifest is part of the assembly, thus making the assembly self-describing.
- An assembly is completely self-describing. An assembly contains metadata information, which is used by the CLR for everything from type checking an security to actually invoking the components methods. As all information is in the assembly itself, it is independent of registry. This is the basic advantage as compared to COM where the version was stored in registry.
- Multiple versions can be deployed side by side in different folders. These different versions can execute at the same time without interfering with each other. Assemblies can be private or shared. For private assembly deployment, the assembly is copied to the same directory as the client program that references it. No registration is needed, and no fancy installation program is required. When the component is removed, no registry cleanup is needed, and no uninstall program is required. Just delete it from the hard drive.
- In shared assembly deployment, an assembly is installed in the Global Assembly Cache (or GAC). The GAC contains shared assemblies that are globally accessible to all .NET applications on the machine.

What are the types of Assembly in .NET?
- Public or Shared or Global
- Private or Application Specific
- Satellite

What is a shared assembly?
Shared assembly is the one which is installed in Global Assembly Cache (GAC). An assembly can be installed in GAC using gacutil -i AssemblyName.dll. Before using the gacutil command, that assembly should be strong named using sn.exe.

What is the use of SN.exe?
SN.exe is used to generate public/private key pair.
Example:

SN –k MyKey.snk
The above line tells SN.exe to create a file called MyKey.snk. This file will contain the public and private key numbers persisted in a binary format.

Output:
Microsoft (R) .NET Framework Strong Name Utility Version 3.5.21022.8
Copyright (c) Microsoft Corporation. All rights reserved.

Key pair written to MyKey.snk

What are the attributes of a strong name?
A strongly named assembly consists of four attributes that uniquely identify the assembly: a file name (without an extension), a version number, a culture identity, and a public key. Since public keys are very large numbers, we frequently use a small hash value derived from a public key. This hash value is called a public key token.

Example:
"MyDll, Version=1.0.8143.0, Culture=neutral, PublicKeyToken=b77a5c561934e078"
"MyDll, Version=1.0.8143.0, Culture="en-US", PublicKeyToken=b77a5c561934e078"
"MyDll, Version=2.0.1264.0, Culture=neutral, PublicKeyToken=b77a5c561934e078"
"MyDll, Version=1.0.8143.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a35"

What is the use of System.Reflection.AssemblyName class?
The System.Reflection.AssemblyName class is a helper class that makes it easy for you to build an assembly name and to obtain the various parts of an assembly’s name. The class offers several public instance properties, such as CultureInfo, FullName, KeyPair, Name, and Version. The class also offers a few public instance methods, such as GetPublicKey, GetPublicKeyToken, SetPublicKey, and SetPublicKeyToken.

What is a public key in an assembly? What is the difference between public key and public key token?
Public keys and private keys are created as a result of sn.exe. The size of public keys makes them difficult to work with. To make things easier for the developer (and for end users too), public key tokens were created. A public key token is a 64-bit hash of the public key.

To output the public key and public key token in the visual studio command prompt, execute the following line:
SN –tp MyKey.PublicKey
Output:
Microsoft (R) .NET Framework Strong Name Utility Version 3.5.21022.8
Copyright (c) Microsoft Corporation. All rights reserved.

Public key is
00240000048000009400000006020000002400005253413100040000010001009d40ffc164b647
39c57f68255e30dea46b653862b8391a526925da58d8c9b7054dfe656dc9e8fe12004b34f7c2d8
c539b4125db78fbe848b060e26f8d203de3b8828e4400a7f6462a850380b931cf0acdc57e16e7a
9d61e959bcfbf876c1ffec9d37a7f07fff71a94496733a80b31e1c92a1942ba25dd5407d69c268
f610f8eb

Public key token is 1d4bea694be65dc8
Note: The SN.exe utility doesn’t offer any way for you to display the private key.

How to associate a key file to an assembly?
When you compile your assembly, you use the /keyfile:<file> compiler switch:
csc /keyfile:MyKey.snk Program.cs

Note: When the C# compiler sees this switch, the compiler opens the specified file (MyKey.snk), signs the assembly with the private key, and embeds the public key in the manifest. Note that you sign only the assembly file that contains the manifest; the assembly’s other files can’t be signed explicitly.

.Net Interview Questions and Answers for Experienced


What is the difference between a thread and a process?

What is the difference between an EXE and a DLL?

What is strong-typing versus weak-typing?

What is the difference between a.Equals(b) and a == b?

What is boxing?

Is string a value type or a reference type?

What is the Global Assembly Cache (GAC)? What problem does it solve?

What is an Interface and how is it different from a Class?

What is Reflection?

Conceptually, what is the difference between early-binding and late-binding?

When would using Assembly.LoadFrom or Assembly.LoadFile be appropriate?

What is an Asssembly Qualified Name? Is it a filename? How is it different?

How is a strongly-named assembly different from one that isn’t strongly-named?

What does this do? sn -t foo.dll

How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization?

What is the difference between Finalize() and Dispose()? (external article)

What is the difference between in-proc and out-of-proc? What technology enables out-of-proc communication in .NET?

What is FullTrust? Do GAC’ed assemblies have FullTrust?

What is the difference between Debug.Write and Trace.Write? When should each be used?

What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?

What is the difference between: catch (Exception e) {throw e;} and catch (Exception e) {throw;} ?

What is the difference between typeof(foo) and myFoo.GetType()?

What is the purpose of XML Namespaces?

What is the difference between an XML "Fragment" and an XML "Document"? (XML Basics)

How would you validate XML using .NET?

What is a PostBack?

What is ViewState? How is it encoded? Is it encrypted? Who uses ViewState? Why is it either useful or evil?

What Session State providers are available in ASP.NET? What are the pros and cons of each?

What is the OO relationship between an ASPX page and its CS/VB code behind file?

How would one implement ASP.NET HTML output caching, caching outgoing versions of pages generated via all values of q= except where q=5 (as in http://localhost/page.aspx?q=5)?

What are HttpHandlers?

What are HttpModules?

What is needed to configure a new extension for use in ASP.NET? For example, what if I wanted my system to serve ASPX files with a *.jsp extension?

How do cookies work? What is an example of Cookie abuse?

What kind of data is passed via HTTP Headers?

How does IIS communicate at runtime with ASP.NET? Where is ASP.NET at runtime in the different versions of IIS (5 to 7)?

Whats the difference between an abstract class and interface? When would you want to use them?

What's the difference between a left join and an inner join?

What's the difference between viewstate and sessionstate?

What's the difference between overriding and overloading a method? Explain how both are done.

What's the difference between protected and internal? What about "protected internal"?

How do short-circuited operators work?

Explain what the StringBuilder class is and why you'd want to use it?

What's the difference between a static method and a non-static method?

What does the "volatile" keyword in C# mean?

Explain what happens when you pass a "ref" or "out" parameter into a method. What's the difference between those two keywords?

What's a weakreference? When would you want to use one?

What's the difference between a DataTable and a DataReader?

What's the difference between a value-type and a reference type?

What does the "readonly" keyword in C# mean?

How to copy dll from gac to a folder


DLLs once deployed in GAC (normally located at c:\windows\assembly) can’t be viewed or used as a normal DLL file. They can’t be directly referenced from VS project. Developers usually keep a copy of the original DLL file and refer to it in the project at development (design) time, which uses the assembly from GAC during run-time of the project.

 

During execution (run-time) if the assembly is found to be signed and deployed in GAC the CLR automatically picks up the assembly from the GAC instead of the DLL referenced during design time in VS. In case the developer has deleted the original DLL or don’t have it for some reason, there is a way to get the DLL file from GAC. Follow the following steps to copy DLL from GAC

 

1. Run regsvr32 /u C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll – shfusion.dll is an explorer extension DLL that gives a distinct look to the GAC folder. Unregistering this file will remove the assembly cache viewer and the GAC folder will be then visible as any normal folder in explorer. 

 

2. Open “%windir%\assembly\GAC_MSIL”.

 

3. Browse to your DLL folder into the deep to find your DLL.

 

4. Copy the DLL somewhere on your hard disk and refer it from there in your project

 

5.    Run “regsvr32 /i %windir%\Microsoft.NET\Framework\<.NET version directory> \shfusion.dll” to re-register the shfusion.dll file and regain the original distinct view of the GAC.

 

References – http://msdn.microsoft.com/en-us/library/34149zk3(VS.71).aspx for additional information on assembly cache viewer (shfusion.dll)

Similar Tags