Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

using reflection , or any means, how can I get the name of a source code file at runtime?

Posted on 2014-04-01
6
Medium Priority
?
444 Views
Last Modified: 2014-04-05
using reflection ,or any means, how can I get the name of a source code  file at runtime?
0
Comment
Question by:HLRosenberger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39970249
What version of .NET and/or Visual Studio are you using?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 668 total points
ID: 39970585
Which source code file? The one from which the executing method comes, or something else?

You can get the source file of the executing method using:
System.Diagnostics.StackTrace stack = new System.Diagnostics.StackTrace(true);
string executingFile = stack.GetFrame(0).GetFileName();

Open in new window

0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 668 total points
ID: 39971448
For this to work, you need to make sure that you "Generate debug info" in the Advanced Compile Options (Compile tab of the project's Properties window) and that you distribute the .pdb file that is generated along with the application.
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 26

Assisted Solution

by:Alan Warren
Alan Warren earned 664 total points
ID: 39977105
Hi HLRosenberger,

I use the following to determine exact source of error using system.reflection.methodbase()
      Try
        ' ...

      Catch ex As Exception
        Dim sf As System.Diagnostics.StackFrame = New System.Diagnostics.StackFrame()
        Dim mb As System.Reflection.MethodBase = sf.GetMethod()
        Session("ErrorMessage") = "Error in " _
          & Context.Request.Url.ToString().Replace(Context.Request.Url.GetLeftPart(UriPartial.Authority) & VirtualPathUtility.ToAbsolute("~/"), "~/") _
          & "." & mb.Name _
          & "<br />" & ex.Message _
          & "<br />" & ex.Source
      End Try

Open in new window

Respectfully yours,
Alan
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 39980521
thanks
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39980775
I see my question was completely ignored. I asked it for a reason. If you're working under .NET 4.5, then you might investigate The CallerFilePathAttribute class.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

610 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