How To Get Error Line Number In Vb.net
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Getting VB.NET line numbers in stack trace up vote 7 down vote favorite 4 I have a VB.NET 2010 Winforms application where I'd like to include line numbers in the stack trace. I've read the following question and answers: how to print out line number during application run in VB.net Which mentions "you always need to include the PDB file with your code, which contains debugging information that is used in situations like this". Under advanced compiler settings I've tried "Generate debug info" as "pdb-only" and "full" for my release build and confirmed that a fresh PDB file is generated in the same directory as my EXE. However the following test code generates a line number of zero for each stack frame and doesn't return a filename: Dim st As StackTrace = New StackTrace(ex) For Each sf As StackFrame In st.GetFrames MsgBox("Line " & sf.GetFileLineNumber() & sf.GetFileName) Next However the following code straight after it generates an otherwise good looking stack trace so it doesn't seem to be a problem with the exception handler in general: ExceptionDetails.Text = ex.GetType.ToString & "(0x" & hr.ToString("X8") & "): " & ex.Message & vbCrLf & ex.StackTrace I can't seem to find any other likely settings under the project configuration and wondered if anyone had ideas on other things that may cause this problem. All the solutions I've found searching here and elsewhere just seem to suggest making sure the PDB is in the same path as the executable. winforms stack-trace vb.net-2010 share|improve this question asked Dec 27 '12 at 0:06 PeterJ 2,14541732 add a comment| 3 Answers 3 active oldest votes up vote 4 down vote accepted From the documentation of the constructor you're calling: The StackTrace is created with the caller's current thread, and does not contain file name, line number, or column information. Try using: Dim st As StackT
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions View All Questions... C# questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware http://stackoverflow.com/questions/14047821/getting-vb-net-line-numbers-in-stack-trace & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge  The Insider News http://www.codeproject.com/Questions/80793/Get-Error-Line-No-in-Vb-net The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ Get Error Line No in Vb.net Rate this: Please Sign up or sign in to vote. See more: VB VB.NET Dear Friends, I have a problem in getting line number when displaying error. the problem details is as follows. 1. From my Debug folder when i run the exe and generate error i can see the line number (as per the below shown code). 2. But when i release the exe to customer and when he gets error. the Line number in this case is always 0. 3. I have found that there is one .pdb file responsible for line number, but the problem is as this file contains source code line i do not want to distribute the same to our customer. ================
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/General ASP.NET/Web Forms/VB.net: How to ALWAYS show the line number of the error VB.net: How to ALWAYS show http://forums.asp.net/t/1816998.aspx?VB+net+How+to+ALWAYS+show+the+line+number+of+the+error the line number of the error [Answered]RSS 2 replies Last post Jun 21, 2012 03:41 PM by Nasser Malik ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts https://bytes.com/topic/visual-basic-net/answers/348765-how-get-line-number-where-error-thrown-caught Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Related Links GuidanceSamplesVideos Reply tvb2727 Participant 892 Points 2378 Posts VB.net: How to ALWAYS show the line number of how to the error Jun 21, 2012 03:36 PM|tvb2727|LINK I am debugging a website I wrote. For some reason in my try/catch, it will show the error message, but no specific line # where the error occurred. How can I ALWAYS know the line # or what decides that? This is a .vb file. VB.net code Catch ex As Exception logging.errors(ex.ToString, how to get error_l) If HttpContext.Current.Session("where") = "cdrive" Then MsgBox(ex.ToString) End If Dim returnstring(0) As String returnstring(0) = False Return returnstring End Try Reply MattsDotNetU... Contributor 2151 Points 513 Posts Re: VB.net: How to ALWAYS show the line number of the error Jun 21, 2012 03:40 PM|MattsDotNetUsername|LINK You need to have the pdb file along with your DLL. Try running the website with those as well as your DLLsand you should see your line number. Reply Nasser Malik Star 12720 Points 2559 Posts Re: VB.net: How to ALWAYS show the line number of the error Jun 21, 2012 03:41 PM|Nasser Malik|LINK If you need the line number for more than just the formatted stack trace you get from Exception.StackTrace, you can use the StackTrace class: try { throw new Exception(); } catch (Exception ex) { // Get stack trace for the exception with source file information var st = new StackTrace(ex, true); // Get the top stack frame var frame = st.GetFrame(0); // Get the line number from the stack frame var line = frame.GetFileLineNumber(); } see http://stackoverflow.com/questions/3328990/c-sharp-get-line-number-which-thrown-expection http://stackoverflow.com/questi
+ Ask a Question Need help? Post your question and get tips & solutions from a community of 418,570 IT Pros & Developers. It's quick & easy. how to get the line number where error was thrown and/or caught P: n/a Mark Kamoski Hi Everyone-- How can one get the line number of where an error was thrown and/or caught? For example, note the following, for use at any given point in a piece of code: ....to get the current Assembly's name, one can use this... System.Reflection.Assembly.GetExecutingAssembly(). GetName().Name ....and, to get the current class's name, one can use this... System.Reflection.MethodBase.GetCurrentMethod().De claringType.Name ....and, to get the current method's name, one can use this... System.Reflection.MethodBase.GetCurrentMethod().Na me ....BUT... ....to get the line number of where an error was thrown and/or caught one can use??? WHAT? Any ideas? (Note that, in short, I would like to get the line number the same way as when DotNet reports an unhandled exception, where it gives the line number of the break.) Please advise. Thank you. --Mark Nov 20 '05 #1 Post Reply Share this Question 5 Replies P: n/a Herfried K. Wagner [MVP] Hello, "Mark Kamoski"