Solved

in C# dll, how to know the calling method's name?

Posted on 2004-09-13
2
1,032 Views
Last Modified: 2008-03-06
I know how to get the calling app's name from the body of the C# dll, but how do i find out that which mehtod of the client app is calling the method of the DLL?

The dll is a common class libary created in C#. Calling app is also created in C#

Thanks!
0
Comment
Question by:cliffairal
  • 2
2 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12047867
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 250 total points
ID: 12047912
using System;
using System.Diagnostics;
namespace ConsoleApplication28
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      class Class1
      {

            private static void TestMethod(int i) {
                  StackFrame sf = new StackFrame(1);
                  StackTrace st = new StackTrace(sf);
                  for(int j=0;j<st.FrameCount;j++) {
                        Console.WriteLine("Method name - " + st.GetFrame(j).GetMethod().Name);
                        Console.WriteLine(st.GetFrame(j).GetMethod().ToString());
                  }      
            }

            [STAThread]
            static void Main(string[] args)
            {
                  try {
                        TestMethod(0);
                  }
                  catch (Exception Ex) {
                        Console.WriteLine(Ex.ToString());
                  }
            }
      }
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now