I found out that AssemblyDefinition.ReadAssembly
doesn't use the cache of DefaultAssemblyResolver
, so at typeRef.Resolve()
the assembly is parsed again and of course the newly added type can't be found.
That's why i switched to
var resolver = new DefaultAssemblyResolver();
resolver.AddSearchDirectory(...);
var asm1 = resolver.Resolve(AssemblyNameReference.Parse(...));
var asm2 = resolver.Resolve(AssemblyNameReference.Parse(...));
...
You have to use this overload of Resolve
because it's the only one which uses the cache and therefore doesn't load the assembly again. I guess this is not intended.
Thank God it's Open Source.