I am generating an Assembly on the fly using Reflection.Emit and then saving it. It contains one Type and a static Main() method in it.
.NET is kind enough to automatically reference a required assembly. However, in Main(), there is a call to a method from another assembly and it doesn’t get referenced in the standard way.
When the assembly is executed, the runtime looks for this assembly and cannot find it, which is a problem.
Reflector can detect this and shows this extra assembly under the ‘depends’ list. How can I retrieve these implicit dependencies using the Reflection API?
Thanks
Thanks for the responses guys, I have managed to resolve the problem.
Here’s what happens:
AssemblyBuilder builder = … // generate assembly
builder.GetReferencedAssemblies(); => It will NOT return a reference to the assembly used in the method body even though I have called Save() already – it seems to return only the assemblies loaded in memory already.
Assembly.ReflectionOnlyLoadFrom(filename).GetReferencedAssemblies() => works fine