Learn the notes. NET Framework Program Design (revised edition)--chapter III Shared assemblies (2)

Source: Internet
Author: User
Tags command line contains hash reference switches
. NET Framework | notes | programs | Design 3.4 Reference Strong-named assemblies
1, the second chapter refers to the use of CSC.exe/reference command-line switches to specify the desired referenced assembly file name. If the file name contains the full path, CSC.exe loads the file under the specified path. If you specify a file without a path, it looks for a referenced assembly in the following directory:
A, the current work path;
b, the directory in which the compiler is currently using the CLR. MSCorLib.dll is always included in the directory (System.Object is defined in this assembly). This directory is similar to the following:
C:\Windows\Micorsoft.NET\Framework\v1.0.3427;
C, any directory specified with the CSC.exe/lib command line switch;
D, the directory specified in any LIB environment variable.

Installation. NET Framework, Microsoft's assembly files are copied to the CLR's directory and the GAC directory, respectively. Copying in the directory where the CLR is located allows us to easily build our own assemblies, while copies in the GAC are used to load these assemblies at run time.
The reason CSC.exe does not find the referenced assembly in the GAC is because the path you need to specify is cumbersome.

2. Response file (response files): is a text file that contains a set of compiler command-line switches. When the CSC.exe command is executed, the compiler opens the response file and uses the command-line switches specified in the response file like a switch that is passed by a common command line.
Example:
A response file MYPROJECT.RSP contains the following text:
/out:myproject.exe
/target:winexe
To enable CSC.exe to take advantage of these settings, you can call it like this:
Csc.exe @MyProject. RSP CodeFile1.cs CodeFile2.cs

The C # compiler supports multiple response files.
When running CSC.exe, it automatically searches the current directory for a local csc.rsp file, and the compiler also searches for a global csc.rsp file in the directory where CSC.exe resides.
When there is a conflict in the local response file and the settings in the global response file, the settings in the local response file override the settings for the global response file, and similarly, the settings that are passed to CSC.exe will overwrite the settings in the local response file.
CSC.RSP contains a command line similar to the following:
/r:systme.dll
/r:accessibility.dll
/r:system.data.dll
Wait
We can also add our own command-line switches to the csc.rsp file if needed.

3.5 Tamper-resistant features of strong-Named assemblies
1. Signing the assembly with a private key ensures that the producer of the Assembly is the holder of the corresponding public key:
A, when the assembly is installed in the GAC directory, the system will hash the contents of the file containing the manifest, and use the resulting hash value to compare with the RSA digital signature embedded in the PE file. If the contents of the same proof assembly file are not tampered with, and you know that we have a public key corresponding to the publisher's private key;
b, the system hashes the contents of other files in the assembly, and then compares the resulting hash values with the hash values stored in the FileDef table in the manifest file. If any mismatches are found, it is proven that at least one of the Assembly's files has been tampered with.

2. When an application needs to bind an assembly, the CLR locates the assembly in the GAC using some of the attributes (name, version, language culture, and public key) of the referenced assembly.
If a referenced assembly is found, the subdirectory in which it resides is returned, and the file that holds the manifest is loaded. This ensures that the runtime-loaded assemblies and compile-time generated programs are lumped together from the same publisher.
If the referenced assembly is not in the GAC:
B, the CLR will look in the base directory of the application, and if it is not found
C, the CLR looks up the private path identified in the application's configuration file
D, if the application is installed using MSI, the CLR will ask the MSI to locate the assembly.
If an assembly binding failure system is not found, a System.IO.FileFoundException exception is thrown.

When a strong-named assembly file is loaded from a non-GAC location, the CLR compares the hash value when the assembly is loaded (when loaded in the GAC, compares the hash value when the program is installed). )。 If a hash value mismatch is detected, the System.IO.FileLoadException exception is thrown.





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.