C # Assembly generation 12, C # How the compiler and CLR find the assembly,

Source: Internet
Author: User

C # Assembly generation 12, C # How the compiler and CLR find the assembly,

This article describes how to find an assembly in C # compiler and CLR runtime, and how to customize the method for searching an assembly in CLR runtime.

 

□C # How to Find the Assembly during the compiler and CLR Runtime

C # Where is the compiler?
-- In C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319

→ Delete All exe and dll files in the as folder of drive F
→ Cache the folder (C: \ Windows \ Microsoft. NET \ assembly \ GAC_MSIL \ Farm \ v4.0 _ 3.3.3.3 _ 863de8402b3a9978) in Farm. dll cut and copy to C: \ Windows \ Microsoft. NET \ Framework \ v4.0.30319folder, that is, put farm.dllto the folder where the cve-compiler csc.exe is located

Now, farm.dllneither saving the folder in the program set, nor saving the fdisk asfolder, and keeping csc.exe in the same folder.
→ Farm. dll is not found in the as folder of drive F.

→ Re-compile MainClass. cs

However, when mainclass.exe is run, an error is returned.

This Note: The above compilation is successful, meaning that the C # compiler can find the Farm. dll assembly in the folder where it is located. However, the Farm. dll assembly is "unknown" during CLR runtime.
When clrruns, Farm. dll is searched in the folder where mainclass.exe is located. If no Farm. dll is found, an error is returned.
Now, copy the Farm. dll in the folder where csc.exe is located to the as folder on the F disk.
Then run mainclass.exe.

This confirms that the CLR runtime searches for the assembly in the folder where the executable file is located.


So,

C # the sequence in which the compiler looks for an assembly is:
1. Search in the C # compiler folder
2. Search in the Global Assembly Cache folder (the Assembly in this folder must be a strong name)
3. Search for executable files in the folder

 

When the CLR is running, the order of the query assembly is:
1. Search in the Global Assembly Cache folder (the Assembly in this folder must be a strong name)
2. Search for executable files in the folder

 

□How to find an assembly during custom CLR Runtime

→ View the current file in the as folder of drive F

→ Create a MyAssemblies folder

→ Move Farm. dll to the newly created MyAssemblies folder

When supervisor runs mainclass.exe, an error is reported.

Create the mainclass.exe. config file in the asfolder.
→ Open it in notepad, write as follows, and save

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <probing privatePath="MyAssemblies" />
        </assemblyBinding>
    </runtime>
</configuration>

The supervisor runs mainclass.exe again, and everything is normal.

 


Summary:
○ .Netsearch is a suffix that can be found in the same way as farm.dlland farm.exe.
○ C # The methods for searching an Assembly vary with the compiler and CLR runtime.
○ In "executable file name .exe. config", set the method for searching the Assembly during CLR running.

 

"C # Assembly series" includes:

C # Assembly series 01, use NotePad to write C # And IL code, use the DOS command to compile the assembly, and run the C # Assembly series 02 program, use NotePad to view the IL code C # Assembly series 03 of the executable assembly, reference multiple module C # Assembly series 04, when an Assembly contains multiple modules, you can understand the keyword internal C # Assembly generation 05, so that the Assembly contains multiple modules C # Assembly generation 06, assembly list, differences between EXE and dll c # Assembly generation 07, tampered with assembly C # Assembly generation 08, set assembly version C # Assembly generation 09, assembly signature C # Assembly Generation 10, strong name assembly C # Assembly generation 11, Global Assembly Cache C # Assembly generation 12, C # compiler and CLR how to find assembly C # Assembly generation 13, how to let CLR select different versions of Assembly

 

References:

Http://www.computersciencevideos.org/created by Jamie King


C Language & |! What are

& Is the address fetch operator used to extract the address of a variable.
For example, if you define a variable, the system will allocate a space in the memory during compilation.
The location of the space in the memory is its address. & Extract its address.
E. g int a; assign an address to it during compilation, for example, 2000; & a is 2000.
If an integer pointer Variable p, p = & a; is defined, the address 2000 of a is assigned to p. P = 2000 after running.
Another example is scanf ("% d", & a). When you enter 3, it first knows the address of a according to & a, and finds the space of a in the memory by the address, write 3 to this space.
* Is a pointer operator, which is opposite to &. It extracts the value of a Variable Based on the address of the variable.
For example, * the value of a is 3 of variable.
The following is a summary of the pointer used in the definition and description.
Int * p; defines a pointer to integer data.
Int * p [n]; defines the pointer array p, which consists of n pointer elements pointing to integer data.
Int (* p) [n]; p is the pointer variable pointing to a one-dimensional array containing n elements.
Int * p (); p is the function that returns a pointer pointing to integer data.
Int (* p) (); p is the pointer to the function. This function returns an integer value.
Int ** p; p is a pointer variable that points to an integer Data Pointer variable.
If you want to learn more about the system, you can refer to tan haoqiang's c Programming (the third edition), which is easy to understand. Is a good C language learning material.

C Language & |! What are

& Is the address fetch operator used to extract the address of a variable.
For example, if you define a variable, the system will allocate a space in the memory during compilation.
The location of the space in the memory is its address. & Extract its address.
E. g int a; assign an address to it during compilation, for example, 2000; & a is 2000.
If an integer pointer Variable p, p = & a; is defined, the address 2000 of a is assigned to p. P = 2000 after running.
Another example is scanf ("% d", & a). When you enter 3, it first knows the address of a according to & a, and finds the space of a in the memory by the address, write 3 to this space.
* Is a pointer operator, which is opposite to &. It extracts the value of a Variable Based on the address of the variable.
For example, * the value of a is 3 of variable.
The following is a summary of the pointer used in the definition and description.
Int * p; defines a pointer to integer data.
Int * p [n]; defines the pointer array p, which consists of n pointer elements pointing to integer data.
Int (* p) [n]; p is the pointer variable pointing to a one-dimensional array containing n elements.
Int * p (); p is the function that returns a pointer pointing to integer data.
Int (* p) (); p is the pointer to the function. This function returns an integer value.
Int ** p; p is a pointer variable that points to an integer Data Pointer variable.
If you want to learn more about the system, you can refer to tan haoqiang's c Programming (the third edition), which is easy to understand. Is a good C language learning material.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.