Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

Howto debug a dll loaded at runtime?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fabio Cannizzo - 15 Dec 2005 23:53 GMT
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 

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.