Mono.Cecil – IAssemblyResolver

One of the important thing you need to know when you start to do real work with Cecil is the IAssemblyResolver


public interface IAssemblyResolver
{
AssemblyDefinition Resolve(AssemblyNameReference name);

AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters);

AssemblyDefinition Resolve(string fullName);

AssemblyDefinition Resolve(string fullName, ReaderParameters parameters);
}

The role of this interface, is to handle module resolving.

As you know, in Cecil there is a difference between TypeDef and TypeRef, and every time toy resolve a type – i.e. get a TypeRef – the IAssemblyResolver work to find the assembly that defines the reference.

By default, each module has its own default resolver. This may work in most of the times, but even if it works, potentially you will keep more than one resolver in memory. And beside that, sometimes you need a custom resolver with custom paths to search in so the default will not work.

So the recommendation is to give to assembly\module reader a custom resolver.
You can find an example of IAssemblyResolver here.

This entry was posted in .NET, C#, Internals and tagged , , , . Bookmark the permalink.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.