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
435 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
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 167 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 167 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 26

Assisted Solution

by:Alan Warren
Alan Warren earned 166 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

792 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