Page 1 of 1
Line numbers in exception?
Posted: Mon Apr 24, 2023 10:03 am
by ic2
When a program crashes in VO, you are almost always able to see where and this often means that you can solve the issue instantly in that indicated line.
In X#, when I get an exception, I do get a JIT debugger window and a kind of call stack, but every line number is 0. From earlier post I thought that adding the .PDB file should give line numbers but it doesn't.
I literally lose average 15 minutes with every unhandled exception (with handled exceptions it's often the same actually, in case someone would reply that) as I need to debug going through my program step by step which takes even more time as the poor VS way of "Entity debug off' doesn't properly work in X#.
Is there any way to at least have an idea where I should locate the source of an error?
Dick
Line numbers in exception?
Posted: Mon Apr 24, 2023 11:53 am
by wriedmann
Hi Dick,
unfortunately there is no line number information in .NET executables, but they are in the pdb files.
Therefore I always build with debug information and deliver both exe and pdb files. In that manner I have always the correct exception callstack.
Wolfgang
Line numbers in exception?
Posted: Mon Apr 24, 2023 2:40 pm
by ic2
Hello Wolfgang,
wriedmann post=26013 userid=336 wrote:unfortunately there is no line number information in .NET executables, but they are in the pdb files.
Therefore I always build with debug information and deliver both exe and pdb files. In that manner I have always the correct exception callstack.
So if I understand you correctly you must deliver a Debug instead of Release version together with the PDB files, and then you get line numbers in such an exception like this one:
- windowsformsunhandledexception.png (8.08 KiB) Viewed 724 times
I don't remember having seen line numbers at all (while this is what I do during developing). Indeed the 0 line numbers are a Release exe (together with this PDB file which doesn't have any use then as I understand).
Dick
Line numbers in exception?
Posted: Mon Apr 24, 2023 2:54 pm
by wriedmann
Hi Dick,
since you can set different options for different compile settings, you can also set to write the line numbers to the pdb file even in production mode. Unfortunately I don't know how to do that with Visual Studio since I work with XIDE.
Wolfgang
Line numbers in exception?
Posted: Mon Apr 24, 2023 3:45 pm
by ic2
Hello Wolfgang,
With your reply I may have found it. On the Solution Explorer, I selected Properties on the main project. Then I went to the option Debug in the left part of the screen. There's a combobox Generate Debug Information. This is empty. I have now selected Pdbonly which seems to go together with Configuration Active/Release.
I copied the new exe & pdf file to my working directory and let's see what this brings.
But I have another issue, see post below:
Dick
Line numbers in exception?
Posted: Mon Apr 24, 2023 3:54 pm
by ic2
I have another issue with error handling. In Winforms we use a DataGrid. Usually only later on a full day, with the program active for hours I suddenly get the following exception (some line numbers included below):
Code: Select all
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.DataGridViewImageCell.PaintPrivate(Graphics g, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates elementState, Object formattedValue, String errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, Boolean computeContentBounds, Boolean computeErrorIconBounds, Boolean paint)
at System.Windows.Forms.DataGridViewImageCell.Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates elementState, Object value, Object formattedValue, String errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
I then end up with a big red cross on the DataGrid which won't go away on refreshing it (no idea what kind of design that is supposed to be but it's a known 'feature' of a Winforms Datagrid).
Now I suspected a method called
Private Method dataGridViewEmails_FormatCells
I embedded it with a TRY..CATCH and yes, I got an index was out of range error. Parameter
index. On it's own none of the above was helpful. The methods mentioned in the error above are not mine and
index is not a variable I use. So I suspect it's a line like this:
iColumn := e:ColumnIndex
or
iRecord := (Int)oDataGridView:Rows[e:RowIndex]:Cells["record"]:Value
Now I have 2 issues:
1 I don't know where the error came from (apart from missing line numbers which may have been solved, but no line of my own code is in the call stack of the above error message
2 The above exception error + the red cross still appears despite that I thought I handled the error in the TRY..Catch and saw that it reached that catch.
I am a bit out of ideas how to find this.
Dick
Line numbers in exception?
Posted: Mon Apr 24, 2023 6:49 pm
by wriedmann
Hi Dick,
these errors are hard to find because they are occurring deep in the framework (or better Windows Forms) code.What I do normally in these cases, is that I google the error message, and most of the time i find then an answer.
I would suspect that an item of your data source goes out of scope and gets garbage collected.
Wolfgang
P.S. please look at this page, maybe it helps you:
https://stackoverflow.com/questions/862 ... on-c-sharp