How to find calling class name and method name in C#

How to find calling class name and method name in C#. I am able to find this information using stacktrace.
 StackTrace st = new StackTrace(true);
 ClassName  =   st.GetFrame(1).GetMethod().ReflectedType.Name,
 MethodName = st.GetFrame(1).GetMethod().Name
But not sure that I will get same result in Release mode. Will this work in Release? if not then what is alternative ?

Please confirm
HPCheetahAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Richard LeeConnect With a Mentor Software EnthusiastCommented:
Yes it will work in Release Mode. However why don't you simply compile the app. in release mode and see if it works.

DaTribe
0
 
lazyberezovskyCommented:
Also you can use
MethodBase.GetCurrentMethod()
0
 
lazyberezovskyCommented:
That's for current method name.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
HPCheetahAuthor Commented:
DaTribe

I tried in release mode in vs 2010, and it is working fine.. but I read from so many other forum that stacktrace is not working in release mode.. so just want to confirm.

0
 
lazyberezovskyCommented:
If you only need calling method, then you can get previous frame, not whole stack:
StackFrame frame = new StackFrame(1);
MethodBase method = frame.GetMethod();

Open in new window

0
 
Richard LeeSoftware EnthusiastCommented:
No comment. I think it works, so do you - plus you tested it and it does. What now?

Under what circumstances do these other sources find it doesn't work?

DaTribe
0
 
HPCheetahAuthor Commented:
It works under release mode too
0
All Courses

From novice to tech pro — start learning today.