15
Assembly facebook.com/apex .tgi twitter.com/ ApextgiNoida pinterest.com/ apextgi

Asp.Net Assembly Programming - A Preliminary Intrduction

Embed Size (px)

DESCRIPTION

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. www.apextgi.in

Citation preview

Page 2: Asp.Net Assembly Programming - A Preliminary Intrduction

Versioning Problem(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 fine, existing applications that depended on a previous version of the shared component might no longer work.

Page 3: Asp.Net Assembly Programming - A Preliminary Intrduction

Versioning Problem(DLL Hell) continue…

To solve this versioning problem .Net introduce the concept of ASSEMBLY.

Assembly simplifies the deployment issue.

.Net solve this versioning problem by making the different –different version of an assembly.

Now the existing applications that depended on a previous version of the shared component also work.

In many ways an assembly is equal to a DLL in today's world.Assemblies are a "logical DLLs."

Page 4: Asp.Net Assembly Programming - A Preliminary Intrduction

What is an assembly?

An assembly is a complied file which consist of all the information which is required for the CLR to deploy the application or RUN the application.

Assembly is also known as PE(Portable Executable file).

When the source code of any language of .Net is compiled,respective compiler comes into picture.

Just after compilation ,compiler generates a file.

This file is called assembly.

Assembly can be in the form of EXE or DLL.

If the sources code has Main() function,then after compilation ,exe will be generated.

If the sources code has not Main() function,then after compilation ,dll will be generated.

Page 5: Asp.Net Assembly Programming - A Preliminary Intrduction

Part of an Assembly

An assembly consist of four part.

Manifest: Manifest explain the versioning information and security policy.

Meta Data: Meta data explain the structure of a class or type of the class.

IL: IL refers to Intermediate Language. It is the code independent to OS or CPU because this code is in symbolic code or known as managed code which is only understandable by CLR.

Resouce: It consist of the information of any image like path.

Page 6: Asp.Net Assembly Programming - A Preliminary Intrduction

Kinds Of An Assembly

There are four types of Assembly-

1-Static assembly or local or private Assembly.

2-Shared assembly or Global or public Assembly.

3-Dynamic Assembly

4-Satalite Assembly

Page 7: Asp.Net Assembly Programming - A Preliminary Intrduction

Private Assembly A private assembly is an assembly that is deployed with an application and is

available for the exclusive use of that application.

That is, other applications do not share the private assembly.

By default, when the source code is compiled ,the compiler generates the Private assembly.

Private assembly does not have the security policy.

If an application wants to access the static assembly ,it must be located on the same folder in which private assembly is located.

Security policy of CLR prevents the access to assemblies kept in different-different folder.

Private assembly does not have A+A(Authentication and Autorisation )

Page 8: Asp.Net Assembly Programming - A Preliminary Intrduction

Shared Assembly

A shared assembly is an assembly available for use by multiple applications on the computer.

Shared assembly contains the security information which is required for the CLR.

Shared assembly can be access by the application which is not kept in the same folder in which assembly is resided.

To use a shared assembly it is required to map the assembly in Global Assembly Cache.

Assemblies shipped with microsoft visual studio.net are shared assemblies.

Page 9: Asp.Net Assembly Programming - A Preliminary Intrduction

Dynamic Assembly

Dynamic assemblies are those assemblies which is created at Run Time.

The System.Reflection.Emit  namespace is used for crating the dynamic assembly.

The System.Reflection.Emit  namespace contains classes that allow a compiler or tool to emit metadata and Microsoft intermediate language (MSIL) and optionally generate a PE file on disk.

Page 10: Asp.Net Assembly Programming - A Preliminary Intrduction

Satalite Assembly

A .NET Framework assembly containing resources specific to a given language.

Using satellite assemblies, you can place the resources for different languages in different assemblies.

The correct assembly is loaded into memory only if the user elects to view the application in that language.

Satellite assemblies give this flexibility

You create any simple text file with translated strings, create resources, and put them into the bin\debug folder.

That's it. The next time, your code will read the Current Culture property of the current thread and accordingly load the appropriate resource.

Page 11: Asp.Net Assembly Programming - A Preliminary Intrduction

Making an Assembly

using System;

namespace myproj

{

Public class employee

{

public string show()

{

return "doing practice of assembly";

}

}

}

DLL never contains the Main() function.

Page 12: Asp.Net Assembly Programming - A Preliminary Intrduction

Making an Assembly continue..

Now save the file with the namespace’s name as-

Myproj.cs

Now comile the file like this-

csc /t:library myproj.cs

Now a file is generated named myproj.dll

This file is known as assembly.

Page 13: Asp.Net Assembly Programming - A Preliminary Intrduction

Using an assembly

To use an assembly the reference must be added in the program like using myproj;

Example-

using System;

using myproj;

class check:employee

{

public static void Main()

{

check c=new check();

string s=c.show();

Console.WriteLine(s);

}

}

Page 14: Asp.Net Assembly Programming - A Preliminary Intrduction

Using an assembly…

Now save the file in the same folder in which myproj.dll is kept.

Save as check.cs

Now compile the program like this-

csc /r:myproj.dll check.cs

Now Run the Program .

Output-

“doing practice of assembly”

Page 15: Asp.Net Assembly Programming - A Preliminary Intrduction

Thank You

Apex TG India

E-20 , Sector 63, Noida

0120 – 4029000/9024/9025/

9027

+91-9953584548

Email id: [email protected]

Stay connected with us for more Chapters on .NET

http://www.apextgi.in