I load an assembly DLL dynamically using
System.AppDomain.CurrentDomain.Load(... ).
I create the istance of an object contained in the assembly and invoke one
of its method.
How can I make the debugger stop within the code of this DLL?
If my question is not clear, please have a look below... Thanks a lot
In ClassLibrary1.dll I have
interface MyInterface {
int MyMethod();
}
In ClassLibrary2.dll I have
public MyClass : MyInterface {
int MyMethod() { retrun 10; );
}
In Main.exe I have
....
FileStream fs = new FileStream(@"ClassLibrary2.dll", FileMode.Open);
byte[] buffer = new byte[(int) fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
Assembly asm = System.AppDomain.CurrentDomain.Load( buffer ); // load the
assembly
Type[] tp = asm.GetTypes();
foreach ( Type t in tp )
if (null != t.GetInterface( "MyInterface" ) ) { // scan for types
which implement MyInterface
// call default constructor with no parameters
Object obj = t.InvokeMember(null, BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance,
null, null, null);
// invole a method
int i = (int) ((MyInterface)obj).MyMethod(); // I would like the
debugger to stop during the execution of MyMethod. How can I do???
}
....
Joshua Flanagan - 16 Dec 2005 01:47 GMT
Assuming you have the ClassLibrary2.dll project loaded in Visual Studio
(along with ClassLibrary1), you should be able to step into the code if
you put a breakpoint on the call to MyMethod.
Curious - do you need to load the assembly as a stream?
If not, your code might be simpler load the assembly like this:
Assembly asm = Assembly.Load("ClassLibrary2");
Joshua Flanagan
http://flimflan.com/blog
Fabio Cannizzo - 17 Dec 2005 12:40 GMT
Hi Joshua.
Thanks for the tip. I had to use AssemblyLoadFile(..) instead of
Assembly.Load(), but now it seems to work (also the debugger).
Regards,
Fabio
> Assuming you have the ClassLibrary2.dll project loaded in Visual Studio
> (along with ClassLibrary1), you should be able to step into the code if
[quoted text clipped - 8 lines]
> Joshua Flanagan
> http://flimflan.com/blog