Monday, May 21, 2007

Structure Of Assemblies

An assembly contains the executable code for a program or class library, along with the metadata (data describing other data), which enables other programs to look up classes, methods, and properties of the objects defined within the assembly.
The metadata acts in two ways:
· As a table of contents, describing what is contained inside the assembly
· As a bibliography describing references to data outside the assembly

Single file .NET assemblies have the following general format:
· Manifest (Assembly Metadata) à references to other assemblies
· Type of Metadata
· MSIL Code
· Resources (if present)

Define Manifest?
A manifest contains metadata describing the name, resources, type and version of the assembly as well as dependencies upon other assemblies. The manifest makes an assembly self-describing, easier to deploy, and not bound to a particular system because of strong data in Windows registry.
The manifest is also called the assembly metadata.
The manifest is the heart of the self-description built into .NET assemblies.

The files that contain executable code are called modules; these contain type metadata and MSIL code.
Resource files contain non-executable code such as images, icons, or message files.


What is the tool used to view the contents of an assembly?
The tool you can use to view the contents of an assembly is Ildasm, the .NET Framework Intermediate Language Disassembler tool. This is a handy tool for viewing and understanding the internal structure of assemblies.

How do you execute Ildasm from the VS Command Line?
· The quickest way to execute Ildasm is to go the start -> All Programs à MS VS 2005 à VS Tools à VS Command Prompt and simply enter Ildasm at the command prompt.
· Another way to execute Ildasm is to add it as an external tool to the VS 2005 development environment; this makes it easier to go back and execute it again without having to leave VS 2005. To do this, go to the Tools menu à External Tools and click Add button in this dialog. …..

Define Assembly Attributes?
Assembly attributes are values that provide information about an assembly. The attributes are divided into the following sets of information:
· Assembly identity attributes.
· Informational attributes.
· Assembly manifest attributes.
· Strong name attributes.

What is AssemblyInfo.cs?
AssemblyInfo.cs is used to set properties of the assembly in the manifest. Double-click on the file to open it and look at the contents.
Each of the statements in square brackets that looks like [assembly: Assembly….] is an attribute, a special syntax in C#.

What is Assembly Culture?
The line following the company and trademark attributes is the AssemblyCulture attribute:
[assembly: AssemblyCulture(“”)].
This sets the national language used for this assembly (English, French, Chinese, and so on) and if it is specified it is a special abbreviation following an international standard.
More information can be found in the System.Glbalization namespace.

Note: you don’t need to set the culture unless you’re distributing different language versions of a component. If doing this then the .NET runtime will automatically search for the version of your assembly that matches the current culture.

For Example: in France you display the French message (using your French message resources and/or code). You mark the appropriate assembly with the correct culture attribute for this to happen.

What is Assembly Version Numbers?
The line following the culture attribute is the AssemblyVersion attribute.
[assembly: AssemblyVersion(“1.0”)]
The version for a .NET assembly has four parts:
Major Version . Minor Version . Build Number . Revision
The BuildNumber and the Revision number in the Assembly Version takes the versioning to a finer level of detail.

What is the Build Number in the AssemblyVersion?
The Build Number indicates which build of the assembly this is; the build number will change every time the assembly is rebuilt. Two assemblies with the same major/minor version number and a differing build number may or may not be compatible.

What is the Revision Number in the AssemblyVersion?
The revision number goes one level deeper and is designed to be used for a patch or a “hot fix” to an assembly that is exactly same as the build number; except for this one bug fix.

VS 2005 assigns version numbers automatically as projects are built, depending on what information is set in the AssemblyVersion attribute.

What is AssemblyVersion attribute?
Within the AssemblyInfo.cs file created by VS 2005, the version number is set with the AssemblyVersion Attribute:
[assembly: AssemblyVersion(“1.0.*)]
The AssemblyVersion attribute allows an asterisk(*) to be specified for the last two parts of the version number. This directs VS 2005 to set the build and revision numbers automatically.

Note: You can also specify the asterisk just for the revision number (as in 1.1.1.*) but not the major and minor version numbers (1.* is not allowed).

Note: You can directly set all the parts of the version by specifying a specific number instead of the asterisk:
[assembly: AssemblyVersion(“1.0.1.2”)]
This will force VS 2005 to produce an assembly wit this specific major, minor, build, and revision number.

How do check the version numbers or the assembly’s version attributes?
Use the Ildasm to check the full version number. For ex, if an end user reports a bug, you can compare the version of the assembly on your computer and the one installed on the end user’s computer. You can tell exactly which version that user has; with the revision and build numbers.

What does the manifest of an assembly contains?
The manifest of an assembly contains the version number of the current assembly as well as the version numbers of the referenced external assemblies.

What is the Version Compatibility?
The .NET runtime checks version numbers when loading assemblies to determine version compatibility. This is done only for shared assemblies.
When the .NET runtime loads a referenced assembly, it checks the version in that assembly’s manifest and compares it to the version stored in the reference to make sure the versions are compatible.
If the assemblies have different major or minor version numbers, they are assumed to be incompatible, and the reference assembly will not load.

What is side-by-side execution?
What if you have program A that uses Shapes 1.0 and program B that uses Shapes 1.1 on the same system?
This is actually taken care of in the .NET runtime; there is a feature called side-by-side execution, which enables Shapes 1.0 and Shapes 1.1 to both be installed on the same computer and each to be available to the programs that need that version.

.NET and COM interop questions

Define Runtime Callable Wrapper (RCW)?
RCW is a metadata wrapper allowing .NET application to call COM Components. The .NET application communicates with a COM component through a managed wrapper of the component called Runtime Callable Wrapper. It acts as managed proxy to the unmanaged COM component.
There are two ways to generate a managed metadata wrapper:
· Using Type Library Importer utility.
· VS.NET IDE
Type Library Importer (tlbimp.exe) is a command line syntax, which converts COM specific type definition in a COM type library into equivalent definitions for a .NET wrapper assembly. By default, the utility gives the wrapper assembly the same name as the COM DLL.

How do we implement COM Interoperability?
· Create Runtime Callable Wrapper out of a COM Component
· Reference the metadata assembly DLL in the project and use its methods and properties.

What is COM?
COM stands for Component Object Model, which is a binary specification for software code re-use. It imposes a standard for the interfaces through which client code talks to component classes. The component’s IUnknown interface helps to maintain a reference count of the number of clients using the component. When this count drops down to zero, the component is unloaded. All components should implement the IUnknown interface. The reference count is maintained through IUnknow::AddRef() and IUnknow::Release() methods, and interface discovery is handled through IUnknow::QueryInterface().

What is the need for Interoperability?
COM components have a different internal architecture from .NET components, hence they are not innately compatible. Most organizations, which have built their enterprise applications on COM objects for their middle tier services, cannot write off the investments on these solutions. These legacy components ought to be exploited by managed code in the .NET framework. This is where Interoperability pitches in; it’s a Runtime Callable Wrapper (RCW) that translates specific calls from managed clients into COM specific invocation requests on unmanaged COM components. The method call on RCW will make .NET components believe that they are talking to just another .NET component.

Describe the advantages of writing a managed code application instead of unmanaged one. What’s involved in certain piece of code being managed?
The advantages include automatic garbage collection, memory management, support for versioning and security. These advantages are provided through .NET FCL and CLR, while with the unmanaged code similar capabilities had to be implemented through third-party libraries or as a part of the application itself.

Are COM objects managed or unmanaged?
Since COM objects were written before .NET, apparently they are unmanaged.

So can a COM object talk to a .NET object?
Yes, through Runtime Callable Wrapper (RCW) or PInvoke.

How do you generate an RCW from a COM object?
Use the Type Library Import utility shipped with SDK. tlbimp COMobject.dll /out:.NETobject.dll or reference the COM library from Visual Studio in your project.

I can’t import the COM object that I have on my machine. Did you write that object?
You can only import your own objects. If you need to use a COM component from another developer, you should obtain a Primary Interop Assembly (PIA) from whoever authored the original object.

How do you call unmanaged methods from your .NET code through PInvoke?
Supply a DllImport attribute. Declare the methods in your .NET code as static extern. Do not implement the methods as they are implemented in your unmanaged code, you’re just providing declarations for method signatures.

Can you retrieve complex data types like structs from the PInvoke calls?
Yes, just make sure you re-declare that struct, so that managed code knows what to do with it.

I want to expose my .NET objects to COM objects. Is that possible?
Yes, but few things should be considered first. Classes should implement interfaces explicitly. Managed types must be public. Methods, properties, fields, and events that are exposed to COM must be public. Types must have a public default constructor with no arguments to be activated from COM. Types cannot be abstract.

Can you inherit a COM class in a .NET application?
The .NET Framework extends the COM model for reusability by adding implementation inheritance. Managed types can derive directly or indirectly from a COM coclass; more specifically, they can derive from the runtime callable wrapper generated by the runtime. The derived type can expose all the method and properties of the COM object as well as methods and properties implemented in managed code. The resulting object is partly implemented in managed code and partly implemented in unmanaged code.

Suppose I call a COM object from a .NET applicaiton, but COM object throws an error. What happens on the .NET end?
COM methods report errors by returning HRESULTs; .NET methods report them by throwing exceptions. The runtime handles the transition between the two. Each exception class in the .NET Framework maps to an HRESULT.

.NET Deployment Questions

What do you know about .NET assemblies?
Assemblies are the smallest units of versioning and deployment in the .NET application. Assemblies are also the building blocks for programs such as Web services, Windows services, serviced components, and .NET Remoting applications.

What is the difference between private and shared assembly?
Private assembly is used inside an application only and does not have to be identified by a strong name. Shared assembly can be used by multiple applications and has to have a strong name.

What is strong name?
A strong name includes the name of the assembly, version number, culture identity, and a public key token.

How can you create a strong name for a .NET assembly?
With the help of Strong Name tool (sn.exe).

How can you tell the application to look for assemblies at the locations other than its own install?
Use the directive in the XML .config file for a given application.

Should do the trick. Or you can add additional search paths in the Properties box of the deployed application.

How can you debug failed assembly binds?
Use the Assembly Binding Log Viewer (fuslogvw.exe) to find out the paths searched.

Where are shared assemblies stored?
Global Assembly Cache.

Where is the global assembly cache located on the system?
Usually C:\winnt\assembly or C:\windows\assembly.

Can you have two files with the same fine name in GAC?
Yes, remember that GAC is a very special folder, and while normally you would not be able to place two files with the same name into a Windows folder, GAC differentiates by version number as well, so it’s possible for MyApp.dll and MyApp.dll to co-exist in GAC if the first one is version 1.0.0.0 and the second one is 1.1.0.0.

So let’s say I have an application that uses MyApp.dll assembly, version 1.0.0.0. There is a security bug in that assembly, and I publish the patch, issuing it under name MyApp.dll 1.1.0.0. How do I tell the client applications that are already installed to start using this new MyApp.dll?
Use publisher policy. To configure a publisher policy, use the publisher policy configuration file, which uses a format similar app .config file. But unlike the app .config file, a publisher policy file needs to be compiled into an assembly and placed in the GAC.

What is delay signing?
Delay signing allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development

Difference between namespace and assembly?
Assembly will contain Namespaces, Classes, Data types it's a small unit of code for deployment.Namespace is used in order to avoid conflict of user-defined classes

Namespace:
· It is a Collection of names wherein each name is Unique.
· They form the logical boundary for a Group of classes.
· Namespace must be specified in Project-Properties.
Assembly:
· It is an Output Unit.
· It is a unit of Deployment & a unit of versioning.
· Assemblies contain MSIL code.
· Assemblies are Self-Describing. [e.g. metadata, manifest]
· An assembly is the primary building block of a .NET Framework application.
· It is a collection of functionality that is built, versioned, and deployed as a single implementation unit (as one or more files).
· All managed types and resources are marked either as accessible only within their implementation unit, or by code outside that unit.

Difference between Namespace, Assembly, and Base classes?
1. A namespace is a collection of different classes.
2. An Assembly is a complied and versioned collection of code and metadata that forms an atomic functional unit. Assemblies take the form of a dynamic link library (.dll) file or executable program file (.exe) but they differ as they contain the information found in a type library and the information about everything else needed to use an application or component.An assembly includes:
a. Information for each public class or type used in the assembly – information includes class or type names, the classes from which an individual class is derived, etc
b. Information on all public methods in each class, like, the method name and return values (if any)
c. Information on every public parameter for each method like the parameter's name and type
d. Information on public enumerations including names and values
e. Information on the assembly version (each assembly has a specific version number)
f. Intermediate language code to execute
g. A list of types exposed by the assembly and list of other assemblies required by the assembly
3. The .NET Base Classes are the means by which you can access much of the core functionality of Windows, as well as perform operations such as data access from .NET code. It consists of a huge number of classes that Microsoft has written to carry out these operations, and which you can call in your code. You can even write classes that inherit from the base classes.

.NET FCL consists of series of classes, interfaces, and value types that can be used to program with. The .NET Framework has types that allow one to easily:
· Create extravagant graphical user interface applications (System.Windows.Forms)
· Access and manipulate data in various database formats (System.Data and System.Xml)
· Dynamically query type information (System.Reflection)
· Perform basic Input/Output operations (System.IO)
· Perform operating system security checks (System.Security)
· Create internet enabled applications (System.Net and System.Net.Sockets)
· Create dynamic web based application, ASP.NET (System.Web)
· Access basic data types, event handlers, and exceptions (System)
All types in the FCL are Common Language Specification (CLS) Compliant.

.NET Assembly Features

· Self Description
· .NET Assemblies and the .NET Framework class Library
· Cross-Language Programming
· Interoperation with COM and other Legacy Code

1. Self-Description
What makes the .NET Component installation much easier?
.NET Assemblies are fully self-describing. All this information (description) is contained within the assembly itself – there is no need to look up information in the Registry or elsewhere about the objects contained within the assembly. This makes installation of a .NET Component much easier and more straightforward than with the existing Windows technologies. It is as easy as copying the assemblies onto the disk of the target system.
The self-description of .NET assemblies includes:
· Names of Objects and Methods
· Data types of parameters
· Information about what version the objects are
· Controls security for the contained objects

2. .NET Framework Class Library (FCL):
The .NET FCL classes are used whenever you call a method from the System namespace with the using System directive.
All the system namespaces belong to the .NET Framework Class Library (FCL). Each class within this library is part of self-describing assembly. For ex, the drawing classes are contained in the System.Drawing.dll assembly.
If you add a reference to this assembly in VS 2005, the compiler will include a reference to that assembly when it builds the assembly for your program. At runtime, the CLR reads the metadata in your program’s assembly to see what other assemblies it needs, then locates and loads those assemblies for your program to use.
Note:
· Assembly contain information from more than one name-space
· A single namespace may spread across several assemblies
For ex, the System.Data.dll assembly actually contains some functionality from both the System.Data and the System.Xml namespaces, while the other functionality in the System.Xml namespace is implemented in the System.Xml.dll assembly. Within your program, you are referring to a namespace when specifying the using directive; the references in you VS 2005 project specify the actual assemblies used.

3. Cross-Language Programming
Assemblies enable cross-language programming, since components can be called from any .NET language. Regardless of the language they were originally written in.

.NET provides a number of features that enable cross-language programming:
· The Common Language Runtime (CLR), which manages the execution of all .NET assemblies
· MSIL, generated by all the .NET language compilers. This is a common standard for the binary code generated by the compilers and is what is executed by the CLR. The CLR also defines the format for storing an assembly’s metadata, and this means that all assemblies, whatever language they were written in, share a common format for storing their metadata.
· The programs written in any .NET languages is CLS-Compliant can share components with full inheritance across language boundaries. The CLS defines the features that languages must support in order to support interoperability with other .NET languages.

4. Interoperation with COM and other Legacy Code
The .NET Framework also allows components or libraries written using COM and other legacy technologies to be used with C# and other .NET Technologies. A wrapper assembly is created for the legacy code that allows it to describe itself to the .NET runtime and convert the COM data types to .NET data types, and allow calls back and forth from the .NET languages to the legacy code and vice versa.
VS 2005 automatically creates a wrapper assembly when you add a reference to a COM component.
Calls made by the .NET client assembly go thru the Wrapper to get the COM Component.
.NET Client Assembly ----------------Wrapper Assembly-----------------COM Component.

.NET Assemblies and Components

What is an Assembly?
An assembly is a file that is automatically generated by the compiler upon successful compilation of every .NET application. It can be either a Dynamic Link Library or an executable file. It is generated only once for an application and upon each subsequent compilation the assembly gets updated. The entire process will run in the background of your application; there is no need for you to learn deeply about assemblies. However, a basic knowledge about this topic will help you to understand the architecture behind a .NET application.

Assembly:
When C# program is compiled, it is packaged into an assembly. An assembly is a .NET executable program (or part of an executable program delivered as a single unit.
It is a file or set of files containing a .NET program or resources supporting a program. When you build a C# windows or console application, the .exe file produced is an assembly. If you build a class library the DLL (Dynamic Link Library) file produced is also an assembly.
All the code in an assembly is built, delivered, and assigned a version number as a single unit. The assembly makes the public classes, properties, and methods visible to other programs. Everything private to your program is kept inside the assembly.

Components
A component is a subprogram or part of a program designed to be used by other programs. In addition, a component is a binary unit that can be used by other programs without having to recompile either the source code of the component itself or the program using the component. This means that 3rd party doesn’t have to provide the source code for their components.
· A component includes any binary subprograms, thus any DLL is by definition a component, since it is a subprogram containing executable code.
· A component requires to provide a means of advertising its contents to other programs. Assemblies provide this advertising ability within .NET.
· A component in the .NET Framework must implement the System.ComponentModel.IComponent interface, which includes methods that can be called by other components to release no-longer-used system resources and to support integration with design tools

Benefits of Components
· Components provide
· Improved reusability
· Flexibility and
· Delivery of subprograms
· Binary reuses saves time and increase reliability
If could share the components (written by others) at the binary level, you wouldn’t have to worry about what programming languages was used to develop the component.

DLL (Dynamic Link Library)
MS introduced the DLL where one or more programs could use a chunk of code stored in a separate file. This worked at a very basic level if the programs were written in the same language (typically C). However, programs needed to know a lot in advance about the DLLs they used, and DLLs did not enable programs to use one another’s data.

DDE (Dynamic Data Exchange)
To exchange data, DDE was developed. This defined format and mechanism for piping data from one program to another, but was not flexible

OLE 1.0 (Object Linking and Embedding)
OLE 1.0 enabled a document such as word to actually contain a document from another program (such as Excel). This was something like components, but OLE 1.0 was not truly a general-purpose component standard.

COM (Component Object Model)
MS implemented COM in windows in the mid-1990s. OLE version 2 and many successor technologies were built on COM.

DCOM (Distributed COM) introduced the ability for COM Components to interact over a network.

COM+ added services that components could call on to ensure high performance in multitier environments
COM works well but is difficult to learn and use, especially when used from C++. COM requires information about components to be inserted into the Windows System Registry, making installation more complex and component removal more difficult.

What is Assembly?Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly.Assemblies are a fundamental part of programming with the .NET Framework. An assembly performs the following functions:
· It contains code that the common language runtime executes. Microsoft intermediate language (MSIL) code in a portable executable (PE) file will not be executed if it does not have an associated assembly manifest. Note that each assembly can have only one entry point (that is, DllMain, WinMain, or Main).
· It forms a security boundary. An assembly is the unit at which permissions are requested and granted.
· It forms a type boundary. Every type's identity includes the name of the assembly in which it resides. A type called MyType loaded in the scope of one assembly is not the same as a type called MyType loaded in the scope of another assembly.
· It forms a reference scope boundary. The assembly's manifest contains assembly metadata that is used for resolving types and satisfying resource requests. It specifies the types and resources that are exposed outside the assembly. The manifest also enumerates other assemblies on which it depends.
· It forms a version boundary. The assembly is the smallest versionable unit in the common language runtime; all types and resources in the same assembly are versioned as a unit. The assembly's manifest describes the version dependencies you specify for any dependent assemblies.
· It forms a deployment unit. When an application starts, only the assemblies that the application initially calls must be present. Other assemblies, such as localization resources or assemblies containing utility classes, can be retrieved on demand. This allows applications to be kept simple and thin when first downloaded.
· It is the unit at which side-by-side execution is supported.
· Assemblies can be static or dynamic. Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in PE files. You can also use the .NET Framework to create dynamic assemblies, which are run directly from memory and are not saved to disk before execution. You can save dynamic assemblies to disk after they have executed.There are several ways to create assemblies. You can use development tools, such as Visual Studio .NET, that you have used in the past to create .dll or .exe files. You can use tools provided in the .NET Framework SDK to create assemblies with modules created in other development environments. You can also use common language runtime APIs, such as Reflection.Emit, to create dynamic assemblies.

What are the contents of assembly?In general, a static assembly can consist of four elements:
· The assembly manifest, which contains assembly metadata.
· Type metadata.
· Microsoft intermediate language (MSIL) code that implements the types.
· A set of resources.

What are the different types of assemblies?Private, Public/Shared, Satellite

What is the difference between a private assembly and a shared assembly?
· Location and visibility: A private assembly is normally used by a single application, and is stored in the application's directory, or a sub-directory beneath. A shared assembly is normally stored in the global assembly cache, which is a repository of assemblies maintained by the .NET runtime. Shared assemblies are usually libraries of code which many applications will find useful, e.g. the .NET framework classes.
· Versioning: The runtime enforces versioning constraints only on shared assemblies, not on private assemblies.

What are Satellite Assemblies? How you will create this? How will you get the different language strings? Satellite assemblies are often used to deploy language-specific resources for an application. These language-specific assemblies work in side-by-side execution because the application has a separate product ID for each language and installs satellite assemblies in a language-specific subdirectory for each language. When uninstalling, the application removes only the satellite assemblies associated with a given language and .NET Framework version. No core .NET Framework files are removed unless the last language for that .NET Framework version is being removed.(For example, English and Japanese editions of the .NET Framework version 1.1 share the same core files. The Japanese .NET Framework version 1.1 adds satellite assemblies with localized resources in a \ja subdirectory. An application that supports the .NET Framework version 1.1, regardless of its language, always uses the same core runtime files.)http://www.ondotnet.com/lpt/a/2637 **

How will u load dynamic assembly? How will create assemblies at run time?**

What is Assembly manifest? what all details the assembly manifest will contain?Every assembly, whether static or dynamic, contains a collection of data that describes how the elements in the assembly relate to each other. The assembly manifest contains this assembly metadata. An assembly manifest contains all the metadata needed to specify the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes. The assembly manifest can be stored in either a PE file (an .exe or .dll) with Microsoft intermediate language (MSIL) code or in a standalone PE file that contains only assembly manifest information.It contains Assembly name, Version number, Culture, Strong name information, List of all files in the assembly, Type reference information, Information on referenced assemblies.

Difference between assembly manifest & metadata?assembly manifest - An integral part of every assembly that renders the assembly self-describing. The assembly manifest contains the assembly's metadata. The manifest establishes the assembly identity, specifies the files that make up the assembly implementation, specifies the types and resources that make up the assembly, itemizes the compile-time dependencies on other assemblies, and specifies the set of permissions required for the assembly to run properly. This information is used at run time to resolve references, enforce version binding policy, and validate the integrity of loaded assemblies. The self-describing nature of assemblies also helps makes zero-impact install and XCOPY deployment feasible.metadata - Information that describes every element managed by the common language runtime: an assembly, loadable file, type, method, and so on. This can include information required for debugging and garbage collection, as well as security attributes, marshaling data, extended class and member definitions, version binding, and other information required by the runtime.

What is Global Assembly Cache (GAC) and what is the purpose of it? (How to make an assembly to public? Steps) How more than one version of an assembly can keep in same place?Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer. You should share assemblies by installing them into the global assembly cache only when you need to.Steps
- Create a strong name using sn.exe tooleg: sn -k keyPair.snk- with in AssemblyInfo.cs add the generated file name eg: [assembly: AssemblyKeyFile("abc.snk")]- recompile project, then install it to GAC by eitherdrag & drop it to assembly folder (C:\WINDOWS\assembly OR C:\WINNT\assembly) (shfusion.dll tool)orgacutil -i abc.dll

If I have more than one version of one assemblies, then how'll I use old version (how/where to specify version number?) in my application?**

How to find methods of a assembly file (not using ILDASM)Reflection

Assemblies
An assembly is the logical unit that contains compiled code targeted at the .NET Framework. An assembly is completely self-describing, and is logical rather than a physical unit, which means that it can be stored across more than one field. If an assembly is stored in more than one file, there will be one main file that contains the entry point and describes the other files in the assembly.
The assembly structure is used for both executable code and library code. The only difference is that an executable assembly contains a main program entry point, whereas a library assembly doesn’t.
An important characteristic of assemblies is that they contain metadata that describes the types and methods defined in the corresponding code. Also it contains assembly metadata that describes the assembly itself.

Assemblies come in two types:
1. Shared Assemblies
2. Private Assemblies

Private Assemblies: are the simplest types. They normally ship with software and are intended to be used only with that software. The usual scenario in which you will ship private assemblies is when you are supplying an application in the form of an executable and a number of libraries, where the libraries contain code that should only be used with that application.

Shared Assemblies: are intended to be common libraries that any other application can use. Because any other s/w can access a shared assembly, more precautions need to be taken against the following risks.
· Name Collisions, where another company’s shared assembly implements types that have the same names as those in your shared assembly.
· The risk of assembly being overwritten by a different version of the same assembly.
The solution to these problems involves placing shared assemblies in a special directory subtree in the file system, known as the global assembly cache (GAC).
Unlike the private assemblies, this cannot be done by simply copying the assembly into appropriate folder – it needs to be specifically installed into the cache. This process can be performed by a number of .NET utilities and involves carrying out certain checks on the assembly.

What are the ways to deploy an assembly?
· An MSI Installer,
· A CAB archive, and
· XCOPY command.

What is a satellite assembly?
When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized modules that modify the core application are called satellite assembly.
A Satellite Assembly is defined as an assembly containing localized resources for another assembly.

What namespaces are necessary to create a localized application?
· System.Globalization
· System.Resources

What is the smallest unit of execution in .NET?
An Assembly.

How do you avoid the risk of name collisions in shared assemblies?
To avoid the risk of name collisions, shared assemblies are given a name based on private key cryptography (private assemblies are simply given the same name as their main file name). This name is known as a strong name, is guaranteed to be unique, and must be quoted by applications that reference a shared assembly.

How do you avoid the risk of overwriting an assembly?Problems associated with the risk of overwriting an assembly are addressed by specifying version information in the assembly manifest and by allowing side-by-side installations.

Friday, May 18, 2007

DLL Hell Problem

DLL (Dynamic Link Library)
MS introduced the DLL where one or more programs could use a chunk of code stored in a separate file. This worked at a very basic level if the programs were written in the same language (typically C). However, programs needed to know a lot in advance about the DLLs they used, and DLLs did not enable programs to use one another’s data.

What is DLL Hell Problem?
Whenever u install your application and the DLL is modified, u need to reinstall the applicationat that time dll hell problem occurs in VB as higher version overwrites the lower version.It will be eliminated by the concept of assemblies in .NET
IN A SIMPLER WAY: The problem of DLL HELL arises only when ,the dll files of the two versions try to use the same memory location, instead of choosing different location, hence the problem of DLL HELL arises in VB6.0.To overcome this VB.Net is Developed.TECHNICAL APPROACH TO "DLL HELL": DLL files of same name in a same directory, but the dlls are of different versions is termed as "DLL HELL".

How does assembly versioning in .NET prevent DLL Hell?
.NET allows assemblies to specify the name and the version of any assemblies they need to run.

Definition of DLL Hell?
Dll hell is basically a technique to remove versioning problem. Means that suppose you have install the 1.0 version of any software in ur system. Then after u also install 1.1 version of that software on that system. This confusion is removed by dll hell.
"DLL Hell" refers to the set of problems caused when multiple applications attempt to share a common component like a dynamic link library (DLL) or a Component Object Model (COM) class. In the most typical case, one application will install a new version of the shared component that is not backward compatible with the version already on the machine. Although the application that has just been installed works well, existing applications that depended on a previous version of the shared component might no longer work. In some cases, the cause of the problem is even more subtle. In many cases there is a significant delay before a user discovers that an application has stopped working. As a result, it is often difficult to remember when a change was made to the machine that could have affected the application. A user may remember installing something a week ago, but there is no obvious correlation between that installation and the behavior they are now seeing. The reason for these issues is that version information about the different components of an application aren't recorded or enforced by the system. Also, changes made to the system on behalf of one application will typically affect all applications on the machine. One reason why it was hard to build an isolated application was the run-time environment typically allowed the installation of only a single version of a component or an application. This restriction means that component authors must write their code in a way that remains backward compatible, otherwise they risk breaking existing applications when they install a new component. In practice, writing code that is forever backward compatible is extremely difficult, if not impossible. Also components were shared because disk space and memory was expensive. In the past few years, hard disk and memory prices have dropped dramatically, and disk space is no longer a premium. But as applications have increased in size and in modularity not so long ago many applications were entirely self-contained in a single .exe file - the DLL sharing issue has not been addressed, and the problem has grown over time.

What is the difference between DLL and EXE?
dll is reusable in another applications........dll is inprocess, dll run with an exe
exe is a standalone, outprocess. exe can run independently
· Dlls cannot be run by themselves as they don't have any entry point (Contains only DllMain()).Where as Exes have entry point(Main()) they can be executed.Usually Dlls are used by other Dlls or Exes.
· exes are self executable,where as dll are not exes are not reusable where we can reuse dllsexes are platform dependent where as dll are not platform independentonly console app ,windows apps,windows service produce exes other all dlls only

In .NET a DLL can contain how many classes?
it's not a good practice to have lot of classes in one dll. It has to be logically divided and compiled as separate dll's. Since the output of any .Net code is an assembly and that assembly contains MetaData(self describing assembly), imagine when there are 1000 classes in one single assembly it will take lot of time toload as the MetaData is huge.

How to hide the methods in DLL?
I created one dll that contains add,sub,mul methods after creating the object thatone like obj.add*******I want to hide remaining method how is it possible.
You can make your methods as private, by using private specifier.
How did the MS overcome with the DLL Hell Problem?
The .NET programming model brings a new standard that addresses these DLL problems, with .NET assembly.

Understanding C# .NET

What is C#?
C# (pronounced C-Sharp) is a new programming language introduced with the Microsoft .NET framework and is no doubt the language of choice in .NET environment. It was first created in the late 1990's as part of Microsoft’s whole .NET strategy. It is a whole new language free of backward compatibility curse and a whole bunch of new, exciting and promising features. It is an Object Oriented Programming language, which at its core, has similarities with Java, C++ and VB.
In fact, C# combines the power & efficiency of C++, simple & clean OO design of Java, and code simplification of Visual Basic. Like Java, C# also does not allow multiple inheritance and use of pointers (in safe and managed code) while it does provide garbage memory collection at runtime, type and memory access checking. But, contrary to java, C# keeps the different useful concepts of C++ like operator overloading, enumerations, pre-processor directives, pointers (in unmanaged and un-safe code), function pointers (in the form of delegates), also promises to have template support (with the name of generics) in next versions. Like VB it also supports the concepts of properties (context sensitive accessor to fields). In addition to this, C# comes up with some new/exciting features like reflections, attributes, marshalling, remoting, threads, streams, data access with ADO.NET, etc. C# programming language is designed from the scratch keeping in mind the Microsoft.Net environment. MS.Net (and thus C#) programs runs on top of the Common Language Runtime (CLR), which provides the runtime support to them.

Define C#?
C# is a simple, modern, object-oriented, and type-safe programming language derived from C and C++.

What can you do with C#?
Using the .NET libraries, you can write all types of internet applications, including HTTP connections, e-mail, and sockets programming.
You can implement .NET web services and create Windows Forms applications.
C# will allow you to use COM objects as well as create your own components.
You can even program ASP.NET and create ADO.NET datasets with C#.This is a rich programming language in which you can do anything you set your mind to.

What are the different types of .NET Applications that you can create Using C#?
Creating ASP.NET Application: creating Web pages with dynamic content. An ASP page is basically an HTML file with embedded chunks of server-side VBScript or JavaScript. When a client browser requests an ASP Page, the Web-server delivers the HTML portions of the page, processing the server-side scripts as it comes to them.
XML Web Services:
Creating Windows Forms
Windows Controls
Windows Services: is a program designed to run in the background in Windows NT/2000/XP/2003. Services are useful where you want the program to be running continuously and ready to respond to events without having been explicitly started by the user.

General Comments about C# Syntax:
Most statements end in a semicolon (;)
Can continue over multiple lines without needing a continuation characters such as underscore (in VB)
Statements can be joined into blocks using curly braces {}
Single-line comments begin with two forward slash characters
Multi-line comments begin with a slash and an asterisk (/*) and end with the same combination reversed (*/)

What is .NET Framework?
The .NET Framework has two main components: the common language runtime and the .NET Framework class library.You can think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and other forms of code accuracy that ensure security and robustness.The class library, is a comprehensive, object-oriented collection of reusable types that you can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET, such as Web Forms and XML Web services.

What are the new features of Framework 1.1 ?
1. Native Support for Developing Mobile Web Applications
2. Enable Execution of Windows Forms Assemblies Originating from the InternetAssemblies originating from the Internet zone—for example, Microsoft Windows® Forms controls embedded in an Internet-based Web page or Windows Forms assemblies hosted on an Internet Web server and loaded either through the Web browser or programmatically using the System.Reflection.Assembly.LoadFrom() method—now receive sufficient permission to execute in a semi-trusted manner. Default security policy has been changed so that assemblies assigned by the common language runtime (CLR) to the Internet zone code group now receive the constrained permissions associated with the Internet permission set. In the .NET Framework 1.0 Service Pack 1 and Service Pack 2, such applications received the permissions associated with the Nothing permission set and could not execute.
3. Enable Code Access Security for ASP.NET ApplicationsSystems administrators can now use code access security to further lock down the permissions granted to ASP.NET Web applications and Web services. Although the operating system account under which an application runs imposes security restrictions on the application, the code access security system of the CLR can enforce additional restrictions on selected application resources based on policies specified by systems administrators. You can use this feature in a shared server environment (such as an Internet service provider (ISP) hosting multiple Web applications on one server) to isolate separate applications from one another, as well as with stand-alone servers where you want applications to run with the minimum necessary privileges.
4. Native Support for Communicating with ODBC and Oracle Databases
5. Unified Programming Model for Smart Client Application DevelopmentThe Microsoft .NET Compact Framework brings the CLR, Windows Forms controls, and other .NET Framework features to small devices. The .NET Compact Framework supports a large subset of the .NET Framework class library optimized for small devices.
6. Support for IPv6The .NET Framework 1.1 supports the emerging update to the Internet Protocol, commonly referred to as IP version 6, or simply IPv6. This protocol is designed to significantly increase the address space used to identify communication endpoints in the Internet to accommodate its ongoing growth. http://msdn.microsoft.com/netframework/technologyinfo/Overview/whatsnew.aspx

Is .NET a runtime service or a development platform?
Ans: It's both and actually a lot more. Microsoft .NET includes a new way of delivering software and services to businesses and consumers. A part of Microsoft.NET is the .NET Frameworks. The .NET frameworks SDK consists of two parts: the .NET common language runtime and the .NET class library. In addition, the SDK also includes command-line compilers for C#, C++, JScript, and VB. You use these compilers to build applications and components. These components require the runtime to execute so this is a development platform.

What are the languages aside from C# are interoperable with the .NET?
1. VB 2005
2. VC++ 2005
3. VJ* 2005
4. Scripting languages
i. JScript.NET
ii. ASP.NET
5. COM and COM+

.NET Security
.NET can really excel in terms of security mechanisms provided by Windows because it can offer code-based security, whereas the Windows only really offers role-based security.
· Role-based security: is based on the identity of the a/c under which the process is running (that is, who owns and is running the process)
· Code-based security: is based on what the code actually does and on how much the code is trusted. The CLR is able to inspect code before running it in order to determine required security permission. The importance of the code-based security is that it reduces the risks associated with running code of dubious origin

Application domains
Application domains are an important innovation in .NET and are designed to ease the overhead involved when running applications that need to be isolated from each other, but that also need to be able to communicate with each other. The classic ex of this is a Web server application, which may be simultaneously responding to a number of browser requests.
Application domains are designed as a way of separating components without resulting in the performance problems associated with passing data between processes.

Error Handling with Exceptions
The .NET Framework is designed to facilitate handling of error conditions using the same mechanism, based on exceptions

NET Framework Classes
One of the biggest benefits of writing managed code is that you get to use the .NET base class library.
The .NET base classes are a massive collection of managed code classes that allow you to do almost any of the tasks that were previously available through the Windows API.

Namespaces
Namespaces are the way that .NET avoids name clashes between classes. They are designed to avoid the situation in which you define a class to represent a customer..
A namespace is no more than a grouping of data types, but it has the effect that the names of all data types within a namespace automatically get prefixed with the name of the namespace. It is also possible to nest namespaces within each other.
The .NET base classes are in a namespace called System. The base class Array is in this namespace, so its full name is System.Array. .NET requires all types to be defined in a namespace.