What is meta data?
Metadata is a binary information that is used to describe a program stored in the common language runtime portable executable (PE) or stored in memory.
Each type and member that is defined and referenced in a module and assembly is described in metadata.
When the code executes, the runtime loads the metadata into memory and references it to discover information about the code's classes, members, inheritance, and so on.
Metadata describes each type and member defined in code in a language-neutral manner.
The meta data stores the following information:
Description of the assembly:
1. Marking (name, version, region, public key)
2. Type of export
3. Other assemblies on which the Assembly depends
4. Security permissions required for operation
Description of the type:
1. Name, visibility, base class, and interface for implementation
2. Members (Methods, fields, properties, events, nesting)
Property:
Other descriptive elements of the decorated type and members.
Many people do not understand why Microsoft is introducing assemblies, because assemblies allow us to separate the logical or physical representations of reusable types.
1. What is an assembly
An assembly is a self-describing installation unit consisting of one or more files, an assembly that can make a DLL or EXE that contains metadata, or it can consist of multiple files, such as resource files, metadata, DLLs, and EXE. An EXE file or DLL file generated by. NET compilation is an assembly. An assembly is a building block of a. NET Framework application, a logical unit that contains compiled code, and creating each project file produces an assembly DLL.
an assembly is a or multiple type definition files and a collection of resource files. The common language Runtime (CLR) operates on assemblies. In most cases, the assembly consists of only one piece of text.
2, the structure of the Assembly
1) Assembly listing 2) type metadata 3) MSIL code 4) resources
3. Assembly List
An important part of an assembly is the assembly manifest, which is part of the metadata, describes the assembly and all the information required to reference it, and lists all the dependencies.
4. Private assembly and shared assembly
Assemblies can be shared, or they can be private.
A private assembly is located in the same directory as the application or in its subdirectories. When working with private assemblies, you do not need to consider naming conflicts or versioning conflicts with other classes. The assemblies referenced during the build process are copied to the application's directory. Private assemblies are the general way to build assemblies, especially when applications and components are established in the same company.
There are some rules that you must follow when using shared assemblies. The assembly must be unique, so there must be a unique name (a strong name). Part of the name is a mandatory version number. Shared assemblies are often required when a component is built by another developer, rather than by the developer of the application, and when a large application is distributed across several small projects.
5. Viewing assemblies
The assembly can be viewed using the command-line tool ILDASM, which is an MSIL (compiled-formed intermediate code) disassembly tool.
In addition to ILDASM,. NET Reflector is another powerful tool for analyzing assemblies.
6. Building Assemblies
A module is a DLL that does not have an assembly attribute (so it is not an assembly, but can be added to an assembly later). What is the function of the module? The module can start the assembly faster because not all classes are in one file and the module is loaded only when needed. Another reason for using modules is that multiple programming languages are required to create an assembly.
7. Properties of the Assembly
When you create a Visual Studio project, the source file AssemblyInfo.cs is automatically generated, which is in the properties of the Solution Explorer. This file is used to configure the assembly manifest.
Assembly: The prefix marks the attribute as the global property of the Assembly. The global properties used for an assembly are independent of a specific language element, and namespaces are used for parameters of assembly properties System.reflection/system.runtime.compiler Services and The class in System.Runtime.InteropServices.
8. Dynamically loading and creating assemblies
During development, a reference to an assembly is added so that it is included in the assembly reference, and the types in that assembly are available to the compiler. You can use the static method of class assembly load ().
9. Loading assembly methods
. There are several ways to load an assembly in net:
One, implicit loading
Assemblies that are not explicitly loaded but referenced, the CLR follows the global Assembly Cache (GAC), the working directory (where the application resides), and the private path directory In order to find and load.
Second, Appdomain.load method
Loads an assembly into a specific program domain, primarily for unmanaged code calls .
Iii. Assembly.Load method
loads an assembly by accepting an assembly identity. If strong-named assembly , the identity includes the assembly name, version, language culture, and public key token. The Load method causes the CLR to look for and load the assembly in accordance with the implicitly-loaded policy. weakly named assembly is simply the name of an assembly without a file name extension, and the CLR does not look in the GAC, if no private directory is specified. It is found in the working directory, such as Assembly.Load ("Math"). The definition of the private directory can be specified in the configuration file. Configuration files such as application MyApp.exe can be defined as MyApp.exe.config. Content:
<?xml version= "1.0" encoding= "Utf-8"?> <configuration> <runtime> <assemblybinding xmlns= "Urn:schemas-microsoft-com:asm.v1" > <probing privatepath= "APP; App1;/> </assemblyBinding> </runtime> </configuration>
The apps and App1 are two directories under the working directory, defined by probing, to store the assemblies that need to be loaded in this directory. If you use an assembly in a directory other than the working directory, you can use the CODEBASE element to define it, and you can find its property content on MSDN.
Iv. Methods of Assembly.LoadFrom
The parameter is the name or path of the file that includes the assembly manifest, including the file extension. If you need to load D:/app/math.dll, you can use the statement:
Assembly a = Assembly.LoadFrom (@ "D:/app/math.dll");
A is the assembly that is loaded.
But there are drawbacks to this approach, and in detail on MSDN, one of my own problems is that after loading an assembly in a non-working directory, it fails to deserialize an object in another assembly using that assembly. The problem is resolved after using the Assembly.Load method or placing the assembly in the working directory.
V. Methods of Assembly.loadfile
Used to load the contents of an assembly file on a specified path. Use the LoadFile method to load and check assemblies that have the same identity but are located in different paths. Unlike LoadFrom, LoadFile does not load files into the LoadFrom context, nor does it use the load path to resolve dependencies. LoadFile is useful in this restricted scenario because LoadFrom cannot be used to load an assembly that identifies the same but has a different path; it loads only the first such assembly.
Vi. Methods of Assembly.LoadWithPartialName
Loads an assembly from the application directory or from the global assembly cache using a partial name. The parameter is an assembly identity that contains the name of the assembly without the file extension. The version of the Assembly, the language culture, and the public key are marked as optional. When this method executes, the CLR first examines the application's XML configuration file to search for the qualifyassembly element, and if so, the element should tell the CLR how to map a part of the assembly identity to a fully qualified identity, and the CRL will look for the assembly according to the usual rules. If the element does not exist, the CRL will be searched in the application's working directory and private path directory using the specified name. If it is still not found, find it in the GAC.
Seven, the traditional VC dynamic library call
Calling the Win32 DLL via P/invoke
Using system.runtime.interopservices;//This is the assembly to be introduced when DllImport is used
[DllImport ("DBAccess.dll", CharSet=CharSet.Auto)]
static extern ulong Findapp (bool bistrue);
Declares the external standard dynamic library, which is the same as Win32API.
Reference:
http://blog.csdn.net/helloguonan/article/details/5914270
http://blog.csdn.net/helloguonan/article/details/5914205
This article comes from the "Ricky's blog" blog, please be sure to keep this source http://57388.blog.51cto.com/47388/1655198
+ C #-Overview of assemblies