The .NET assembly is the standard for components developed with the Microsoft.NET. Dot NET assemblies may or may not be executable, i.e., they might exist as the executable (.exe) file or dynamic link library (DLL) file. All the .NET assemblies contain the definition of types, versioning information for the type, meta-data, and manifest. The designers of .NET have worked a lot on the component (assembly) resolution.
There are two kind of assemblies in
.NET;
- private
- shared
Private
assemblies are simple
and copied with each calling assemblies in the calling assemblies folder.
Shared
assemblies (also
called strong named assemblies) are copied to a single location (usually the
Global assembly cache). For all calling assemblies within the same application,
the same copy of the shared assembly is used from its original location. Hence,
shared assemblies are not copied in the private folders of each calling
assembly. Each shared assembly has a four part name including its face name,
version, public key token and culture information. The public key token and
version information makes it almost impossible for two different assemblies
with the same name or for two similar assemblies with different version to mix
with each other.
An assembly can be a single file or
it may consist of the multiple files. In case of multi-file, there is one
master module containing the manifest while other assemblies exist as
non-manifest modules. A module in .NET is a sub part of a multi-file .NET
assembly. Assembly is one of the most interesting and extremely useful areas of
.NET architecture along with reflections and attributes, but unfortunately very
few people take interest in learning such theoretical looking topics.
What are the
basic components of .NET platform?
The basic components of .NET
platform (framework) are:
.Net
Applications
(Win Forms,Web Applications,Web
Services)
|
Data(ADO.Net) and XML Library
|
FrameWork Class Library(FCL)
(IO,Streams,Sockets,Security,Reflection,UI)
|
Common Language
Runtime(CLR)
(Debugger,Type Checker,JITer,GC)
|
Operating System
(Windows,Linux,UNIX,Macintosh,etc.,)
|
Common Language Runtime (CLR):
The most important
part of the .NET Framework is the .Net Common Language Runtime (CLR) also
called .Net Runtime in short. It is a framework layer that resides above the
Operating System and handles/manages the execution of the .NET applications.
Our .Net programs don't directly communicate with the Operating System but
through CLR.
MSIL (Microsoft Intermediate Language) Code:
When we compile
our .Net Program using any .Net compliant language like (C#, VB.NET, C++.NET)
it does not get converted into the executable binary code but to an
intermediate code, called MSIL or IL in short, understandable by CLR. MSIL is
an OS and H/w independent code. When the program needs to be executed, this
MSIL or intermediate code is converted to binary executable code, called native
code. The presence of IL makes it possible the Cross Language Relationship as
all the .Net compliant languages produce the similar standard IL code.
Just In Time Compilers (JITers):
When our IL
compiled code needs to be executed, CLR invokes JIT compilers which compile the
IL code to native executable code (.exe or .dll) for the specific machine and
OS. JITers in many ways are different from traditional compilers as they, as
their name suggests, compile the IL to native code only when desired e.g., when
a function is called, IL of function's body is converted to native code; just
in time of need. So, the part of code that is not used by particular run is not
converted to native code. If some IL code is converted to native code then the
next time when its needed to be used, the CLR uses the same copy without
re-compiling. So, if a program runs for sometime, then it won't have any just
in time performance penalty. As JITers are aware of processor and OS exactly at
runtime, they can optimize the code extremely efficiently resulting in very robust
applications. Also, since JITer knows the exact current state of executable
code, they can also optimize the code by in-lining small function calls (like
replacing body of small function when its called in a loop, saving the function
call time). Although, Microsoft stated that C# and .Net are not competing with
languages like C++ in efficiency, speed of execution, JITers can make your code
even faster than C++ code in some cases when program is run over extended
period of time (like web-servers).
Framework Class Library (FCL):
.NET Framework
provides huge set of Framework (or Base) Class Library (FCL) for common, usual
tasks. FCL contains thousands of classes to provide the access to Windows API
and common functions like String Manipulation, Common Data Structures, IO,
Streams, Threads, Security, Network Programming, Windows Programming, Web
Programming, Data Access, etc. It is simply the largest standard library ever
shipped with any development environment or programming language. The best part
of this library is they follow extremely efficient OO design (design patterns)
making their access and use very simple and predictable. You can use the
classes in FCL in your program just as you use any other class and can even
apply inheritance and polymorphism on these.
Common Language Specification (CLS):
Earlier we used
the term '.NET Compliant Language' and stated that all the .NET compliant
languages can make use of CLR and FCL. But what makes a language '.NET
compliant language'? The answer is Common Language Specification (CLS).
Microsoft has released a small set of specification that each language should
meet to qualify as a .NET Compliant Language. As IL is a very rich language, it
is not necessary for a language to implement all the IL functionality, rather
it meets the small subset of it, CLS, to qualify as a .NET compliant language,
which is the reason why so many languages (procedural and OO) are now running
under .Net umbrella. CLS basically addresses to language design issues and lays
certain standards like there should be no global function declaration, no
pointers, no multiple inheritance and things like that. The important point to
note here is that if you keep your code within CLS boundary, your code is
guaranteed to be usable in any other .Net language.
Common Type System (CTS):
.NET also defines
a Common Type System (CTS). Like CLS, CTS is also a set of standards. CTS
defines the basic data types that IL understands. Each .NET compliant language
should map its data types to these standard data types. This makes it possible
for the 2 languages to communicate with each other by passing/receiving
parameters to/from each other. For example, CTS defines a type Int32, an
integral data type of 32 bits (4 bytes) which is mapped by C# through int and
VB.Net through its Integer data type.
Garbage Collector (GC):
CLR also contains
Garbage Collector (GC) which runs in a low-priority thread and checks for
un-referenced dynamically allocated memory space. If it finds some data that is
no more referenced by any variable/reference, it re-claims it and returns the
occupied memory back to the Operating System; so that it can be used by other
programs as necessary. The presence of standard Garbage Collector frees the
programmer from keeping track of dangling data.
Q:What is Metadata?
A: Metadata is binary information describing your program that is stored either in a common language runtime portable executable (PE) file or in memory. When you compile your code into a PE file, metadata is inserted into one portion of the file, while your code is converted to Microsoft intermediate language (MSIL) and inserted into another portion of the file. Every type and member defined and referenced in a module or assembly is described within metadata. When code is executed, the runtime loads metadata into memory and references it to discover information about your code's classes, members, inheritance, and so on.
A: Metadata is binary information describing your program that is stored either in a common language runtime portable executable (PE) file or in memory. When you compile your code into a PE file, metadata is inserted into one portion of the file, while your code is converted to Microsoft intermediate language (MSIL) and inserted into another portion of the file. Every type and member defined and referenced in a module or assembly is described within metadata. When code is executed, the runtime loads metadata into memory and references it to discover information about your code's classes, members, inheritance, and so on.
·
What does Metadata do?
Metadata describes every type and member defined in your code in a language-neutral manner. Metadata stores the following information:
Metadata describes every type and member defined in your code in a language-neutral manner. Metadata stores the following information:
o Description of the assembly.
§
Identity (name, version,
culture, public key).
§
The types that are
exported.
§
Other assemblies that
this assembly depends on.
§
Security permissions
needed to run.
o Description of types.
§
Name, visibility, base
class, and interfaces implemented.
§
Members (methods,
fields, properties, events, nested types).
o Attributes
§
Additional descriptive
elements that modify types and members.
·
What are the benefits of
Metadata?
Metadata is the key to a simpler programming model, eliminating the need for Interface Definition Language (IDL) files, header files, or any external method of component reference. Metadata allows .NET languages to describe themselves automatically in a language-neutral manner, unseen by both the developer and the user. Additionally, metadata is extensible through the use of attributes. Metadata provides the following major benefits:
Metadata is the key to a simpler programming model, eliminating the need for Interface Definition Language (IDL) files, header files, or any external method of component reference. Metadata allows .NET languages to describe themselves automatically in a language-neutral manner, unseen by both the developer and the user. Additionally, metadata is extensible through the use of attributes. Metadata provides the following major benefits:
o Self-describing files
Common language runtime modules and assemblies are self-describing. A module's metadata contains everything needed to interact with another module. Metadata automatically provides the functionality of IDL in COM, allowing you to use one file for both definition and implementation. Runtime modules and assemblies do not even require registration with the operating system. As a result, the descriptions used by the runtime always reflect the actual code in your compiled file, which increases application reliability.
Common language runtime modules and assemblies are self-describing. A module's metadata contains everything needed to interact with another module. Metadata automatically provides the functionality of IDL in COM, allowing you to use one file for both definition and implementation. Runtime modules and assemblies do not even require registration with the operating system. As a result, the descriptions used by the runtime always reflect the actual code in your compiled file, which increases application reliability.
o Language Interoperability and easier
component-based design
Metadata provides all the information required about compiled code for you to inherit a class from a PE file written in a different language. You can create an instance of any class written in any managed language (any language that targets the common language runtime) without worrying about explicit marshaling or using custom interoperability code.
Metadata provides all the information required about compiled code for you to inherit a class from a PE file written in a different language. You can create an instance of any class written in any managed language (any language that targets the common language runtime) without worrying about explicit marshaling or using custom interoperability code.
o Attributes
The .NET Framework allows you to declare specific kinds of metadata, called attributes, in your compiled file. Attributes can be found throughout the .NET Framework and are used to control in more detail how your program behaves at run time. Additionally, you can emit your own custom metadata into .NET Framework files through user-defined custom attributes. For more information, see Extending Metadata Using Attributes.
The .NET Framework allows you to declare specific kinds of metadata, called attributes, in your compiled file. Attributes can be found throughout the .NET Framework and are used to control in more detail how your program behaves at run time. Additionally, you can emit your own custom metadata into .NET Framework files through user-defined custom attributes. For more information, see Extending Metadata Using Attributes.
No comments:
Post a Comment