Mono.cecil Modify the target. NET IL code to save the Times exception handling.

Source: Internet
Author: User

Use Mono.cecil to save the Times "Failed to resolve assembly: ' xxxxxx, Version=xxxxx,culture=xxxxx," for the Il modification of the target. NET DLL program. Publickeytoken=xxxxxxx ' "Exception.

Debug with Dnspy, originally because the modified target DLL and its own program is not the same directory, when it is necessary to use the DLL referenced by the target DLL when the Mono.cecil only in their own directory for the search match,

If the corresponding DLL file is not found, the above exception information will be reported.

There are two ways to resolve this:

The first one: simply copy the corresponding DLL to the directory where the program itself is located.

The second one: Add the target directory that mono.cecil can search in the program.

            Defaultassemblyresolver resolver = new Defaultassemblyresolver ();            Resolver. Addsearchdirectory (info. DirectoryName); Add target directory              readerparameters parameters = new Readerparameters ()            {                assemblyresolver = resolver,// The object of the target directory will be added as a parameter to assemblyresolver                Readsymbols = False,            };                        Assemblydefinition asm = assemblydefinition.readassembly (file, parameters); Use the above parameters to complete the target directory of the specified and search

  

Mono.cecil Modify the target. NET IL code to save the Times exception handling.

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.