This period of time for tracking a bug, and finally found that the framework of the problem, which makes people somewhat hopeless. So I made a post to the Microsoft Forum, hoping to get some help. Although the Forum smart to be able to determine whether the landlord is the MSDN subscribers, in order to solve the problem as soon as possible (the legend of MSDN subscribers to the issue can be answered within two days, was also very proud of the company to purchase the MSDN Subscription account), but the response is "Could you file a bug report For this issue through Connect? "Again, after the despair of the chilling ah."
Once you've seen Payeasy's ads, you've got the following, how to modify the. NET Framework:
Here we take the example of modifying the GUID class, and we will modify the inner construction of this class so that it always constructs an object with a value of 0 (00000000-0000-0000-000000000000)
1, know who you want to modify (Name of DLL) This is simple, flipping through MSDN, you should be able to find out which class library you are calling, or use reflector to get more detailed information. As you know from MSDN, the GUID class is in mscorlib.dll
2, Find the DLL you want to modify, and copy it out so that you can modify mscorlib.dll in the GAC, unfortunately, Windows only allows you to enjoy it silently (albeit with impatience) in a way that is "invisible to the eye." We now need to find out the actual path of the DLL in the operating system. 2.1 Download Filemon, which is used to monitor the file is accessed, we can find the file path 2.2 through him to write a small program, let the program to access (reference) you need to find the path of the file, here is our The mscorlib
static void Main (string[] args) {GUID guid = guid.newGUID ();
Console.WriteLine (GUID);
Console.read (); }
The GUID in the code as well as the console etc will access mscorlib.dll 2.3 run Filemon, let him go to monitor mscorlib's access, because we do not know mscorlib specific path (nonsense), but we at least know it in C:\WINDOWS\ Assembly (at least in the system disk), then we will put this folder and all of its files to watch it: 2.4, run our applet, Filemon will monitor all access to C:\WINDOWS\assembly, and will contain mscorlib of the highlight , double-clicking an entry in the list will automatically open the folder where the file is located: OK, now find the DLL file, copy it out for us to modify and record its path for future use (C:\WINDOWS\assembly\GAC_32\mscorlib\ 2.0.0.0__b77a5c561934e089). In addition, it is recommended to back up the copied DLL.
3, using ILDASM to decompile the DLL, generate the intermediate language (IL) file , we will modify the Il file ILDASM is a. NET self-contained anti-compilation tool that can be found in the SDK, but can be used with the console of VS (using the method, refer to MSDN) and then get the Il file for that assembly
It is actually a text file, so you can open it directly for editing, but it is recommended to use the notepad++ or UltraEdit text editor, but it seems to be a bit of a crash after opening, the ocean, how to find the code we need to modify the location of the
4, using reflector to view the definition of the class or method you are looking for, open reflector, find the class or method you are looking for, and view its definition, assuming we need the Guid.NewGuid () method:
Switch to Il view: OK, with the Il fragment, it is easy to find the method in the ocean of mscorlib.dll.il (CTRL-F)
5, modify the IL code to find the corresponding method in notepad++ or UltraEdit. We find that NewGuid () is actually calling its GUID (bool) method, which we can replace with the default constructor (the default constructor constructs a GUID of 00000000-0000-0000-000000000000) When you call the NewGuid () method, you always return a value of 0, or you can pass in true when you call the GUID (BOOL), which we use:
. methodPublicHidebysigStatic valuetype System.Guid NewGuid ()CilManaged{//Code size 7 (0x7) . maxstack8il_0000: ldc.i4.0 il_0001: newobj instance void system.guid::.ctor (bool) il_0006: ret } // end of method guid::newguid
il_0000 in the above code : ldc.i4.0 means 0 (false) as a 4-byte integer into the stack, we will change 0 to 1:
. methodPublicHidebysigStatic valuetype System.Guid NewGuid ()Ai.Managed{//Code size 7 (0x7) . maxstack8il_0000: ldc.i4.1 il_0001: newobj instance void system.guid::.ctor (bool) il_0006: ret } // end of method guid::newguid
(Note that the operation here is very simple, so it is simply modified, if for more complex operations please first learn about IL knowledge) and then save your changes.
6, compile IL code, generate a new DLL using MS-provided ILAsm, you can compile IL files into DLLs: (Don't forget to close the text editor before compiling, such as UltraEdit will monopolize the file and cause it to be inaccessible)
7, put the modified DLL back to the GAC you might think that the method mentioned on MSDN installs it in the GAC just like installing your own normal assembly, presumably to guess that this is not possible, otherwise "unsafe". Or, we just did not record the path of the mscorlib, directly copy and paste into the cover is not on the line, maybe, maybe not, just so say no, the reason is likely to have two, one is not let the access page does not let coverage, the second is the program. NET Program runtime checks the assembly version. Then try it: direct access to the specified path is not possible, as shown: But it doesn't matter, we can access the directory through a third-party tool, you can double-click the entry to open the corresponding file directory through the Filemon, There is also a more common convenient way to use Totalcommander, which provides easy access to various hidden paths of windows.
Drag and drop files to the corresponding directory to overwrite them.
8. Remove the native image of the assembly (native image) back to the Filemon monitoring mscorlib access, you may find that our applet directly accesses the mscorlib.dll, Instead, a file called Mscorlib.ni.dll (in C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\ 9adb89fa22fd5b4ce433b5aca7fb1b07\ path), which is the native image of mscorlib.dll (native image), A friend who cares about. NET optimization should know that we can use the NGen to create an assembly cost machine image to improve the speed of operation. Then the program will go directly to the image instead of the mscorlib.dll we modified, which will cause our changes to see no effect. So we're going to remove that image. Why delete, instead of overwriting the modified mscorlib.dll using NGen to generate a new image? The reason is very simple, everyone think about it. First, use the NGen Uninstall command to unload the local image from the native image cache, and then use Totalcommander to remove it (note that applications that can have references to the overridden assemblies are closed first, it's best to restart the computer and not be able to delete it in safe mode)
9, verify the results:
Classprogram {staticvoidMain (String[] args) {Guid guid1 = Guid.NewGuid (); Guid Guid2 = Guid.NewGuid ();
Console.WriteLine ("The firstGUID: {0}", GUID1); Console.WriteLine ("Thesecond GUID: {0}", Guid2);
Console.read (); }
If you use the MS original mscorlib.dll we will get output similar to the following: Use our modified mscorlib.dll:
(also, it's worth noting that Visual studio's references to some assemblies come from C:\Program files\reference assemblies, so you should overwrite some assemblies if you want to affect the VS reference) C:\Program Files\Reference the corresponding file under assemblies. mscorlib not needed here)
Reprint: http://www.cnblogs.com/zhouyinhui/archive/2009/06/04/1496485.html
How to modify the. NET Framework