471,599 Members | 1,227 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,599 software developers and data experts.

Howto debug a dll loaded at runtime?

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???
}
.....
Dec 16 '05 #1
2 3070
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
Dec 16 '05 #2
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

"Joshua Flanagan" <jo**@msnews.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
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

Dec 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Alexander Eisenhuth | last post: by
reply views Thread by Eric Twietmeyer | last post: by
10 posts views Thread by Scott | last post: by
1 post views Thread by Fredrik Melin | last post: by
10 posts views Thread by Brett | last post: by
9 posts views Thread by =?Utf-8?B?VGhvbWFzIFcuIEJyb3du?= | last post: by
2 posts views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.