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.

Advertisements
This entry was posted in .NET, c# and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s