Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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.
 
================Source Snippet==============================
Dim trace As New System.Diagnostics.StackTrace(ex, True)
MessageBox.Show("Line: " + trace.GetFrame(0).GetFileLineNumber().ToString)
============================================================
 
Any urgent help on this will be highly appreciated.
 
Thanks and Regards,
Jignesh Patel
Posted 12-May-10 3:38am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If it's compiled in release mode and not published, you can still get the line number. You just need to change a setting.
 
Go to the Project Properties
Click on the Compile tab
Click Advanced Compile Options.
Select Full or pdb-only from the Generate debug info ComboBox.
 
This will work if you are using the Build option.
 
If however, you are Publishing it, I don't think you'll be able to get the line number.
 
The best idea would be to put specific lines that could throw an exception into their own Try/Catch block.
 
I've seen instances like:
Try
  Dim regKey as RegistryKey
  regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\DataCubeUtility", False)
  Dim filePath as String = regKey.GetValue("DataCubeObjectPath")
  
  Dim serializer as Serialization.XmlSerializer = Nothing
  serializer = New Serialization.XmlSerializer(GetType(myCubeClasses.myCubeDef))
 
  Dim dataFile as New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None)
 
  myCubeType = serializer.Deserialize(dataFile)
 
  dataFile.Close()
  dataFile.Dispose
Catch ex as Exception
  MessageBox.Show(ex.Message)
End Try
 
That is a huge waste of a Try/Catch block. The majority of that will never throw an error. You should break it down and check things yourself. Put the things that could throw an error into it's own Try/Catch block and then customize the message so you know where the error was...as in:
Dim regKey as RegistryKey
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\DataCubeUtility", False)
If regKey Is Nothing Then
  MessageBox.Show("No valid Registry Key")
  Return
End If
 
Dim filePath as String = regKey.GetValue("DataCubeObjectPath")
If Not File.Exists(filePath) Then
  MessageBox.Show("File " & filePath & " does not exist")
  Return
End If
 
Dim serializer as Serialization.XmlSerializer = Nothing
 
Try
  serializer = New Serialization.XmlSerializer(GetType(myCubeClasses.myCubeDef))
Catch ex as Exception
  MessageBox.Show("Unable to create the serializer" & vbNewLine & _
                  "ex.Message: " & ex.Message & vbNewLine & _
                  "ex.StackTrace: " & ex.StackTrace)
  Return
End Try
 
'etc...
 
If you did that, you wouldn't need the line numbers.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I don't think the StackTrace is available when compiled in Release mode.
 
MSDN Info on StackTrace[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hi,
 
Thanks guys for all your help.
 
But after much googling i have found one solution. I have used on tool
MZTools V 6.
 
It has its own custom error line number and using the Erl function i can even get the line number in Release mode without using .pdb file.
 

Please suggest if you have any better solution.
 

Thanks and Regards,
Jignesh Patel.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Actually, I did find the answer if you're using ClickOnce deployment.
 
Go back to the Project Properties.
Click on the Publish Tab.
Click the Application Files button.
Check the box at the bottom-left to Show all files.
 
This will show all of the files, including the pdbs.
 
Just include everything. This will give you the line numbers.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 861
1 Kishore Pogaru 265
2 OriginalGriff 240
3 Volynsky Alex 205
4 Richard Deeming 140
0 OriginalGriff 5,640
1 Sergey Alexandrovich Kryukov 4,693
2 CPallini 4,540
3 George Jonsson 3,132
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 13 May 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100