Thanks JB, that clears things up. I'll give that a try. On Fri, Aug 19, 2011 at 5:43 PM, Jb Evain <[email protected]> wrote:
> Hi, > > On Fri, Aug 19, 2011 at 9:26 AM, Hendry Luk <[email protected]> wrote: > > I've attached a repro test. > > Cheers > > Thanks for the test. > > The issue lies in the fact that when you read an assembly, by default, > it doesn't register itself into the resolver. You can fix it easily by > doing something like: > > class RegisteringResolver : DefaultAssemblyResolver > { > public AssemblyDefinition ReadAssembly(string file) > { > var assembly = AssemblyDefinition.ReadAssembly(file, > new > ReaderParameters { AssemblyResolver = this }); > RegisterAssembly(assembly); > return assembly; > } > } > > [TestFixture] > public class TypeDefinitionEqualityTest > { > [Test] > public void > ResolvingWithReflectionType_ShouldReturnEqualTypeDefinition() > { > var resolver = new RegisteringResolver(); > var asm = > resolver.ReadAssembly(Assembly.GetExecutingAssembly().GetName().Name > + ".dll"); > > var thisType = GetType(); > var cecilType = asm.MainModule.Types.First(x => > x.Name == > thisType.Name).Resolve(); > > Assert.AreEqual(cecilType, > cecilType.Module.Import(thisType).Resolve()); > } > } > > And making sure all assemblies are read through the registering resolver. > > Jb > > -- > -- > mono-cecil -- -- mono-cecil
