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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richard LeeSoftware 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lazyberezovskyCommented:
Also you can use
MethodBase.GetCurrentMethod()
0
lazyberezovskyCommented:
That's for current method name.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.