Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Posted: February 16, 2005
Please note: Portions of this transcript have been edited for clarity
Introduction
Andy Q (Moderator):
Welcome to today’s chat. Our topic is Debugging VB.NET Applications Questions, comments, and suggestions are welcome.
Andy Q (Moderator):
We are pleased to welcome our Experts for today’s chat. I will have them introduce themselves now.
LisaFeig (Expert):
Hi. My name is Lisa Feigenbaum. I'm a Program Manager on the VB Team. I work on the editor, debugger, VB profile, and starter kits. I look forward to chatting with you.
DVerma_MS (Expert):
Hi! I am Deeptanshu Verma (just call me Deep), and I am a QA in the Visual Studio debugger team.
ScottNo (Moderator):
Hi, I'm Scott Nonnenberg. I'm a Program Manager on the Visual Studio debugger. You can find my blog at https://blogs.msdn.com/ scottno. Have you tried out debugger visualizers yet?
Start of Chats
DVerma_MS (Expert):
Q: VB.NET What options do I have to select or references to add to debugger? This stuff works fine when executed with no Breakpoints. Trying to Debug, however, i = Form.ActiveForm.Height gives me the “System.NullReferenceException – Object
A: Hi! This is a strange error and I cannot repro this. Could you please tell me more about the app? I used a VB Winforms app, added a button, put this code in there, set a bp on and after it and could hit them successfully. Is the difference in the repro scenarios only setting of the debugger or is it possible you are running different versions of the exe in the debug/nodebug cases?
ScottNo (Moderator):
Q: Is they any way of speeding up the debugger for ASP.NET Applications(I'm unsure if this chat covers this)?
A: Perhaps. Could you tell me some more information? What version of VS are you using? How exactly are you debugging your ASP.NET application? What exactly is too slow?
Andy Q (Moderator):
Please remember to use the "submit a question" radio button to ask a question, thanks!
LisaFeig (Expert):
Q: What are the limits to E&C; when stopped in the debugger?
A: You are correct, in pointing out that there are certain changes that are not allowed during break mode. Examples of these include changes to declaration statements, such as public methods, public fields, or class declarations. These changes are not allowed because they change the public definition of types, and therefore will cause problems to other code using those types. Note that although these changes are not allowed during break mode, you can still go ahead and validly make those changes to your code upon returning to design mode.
WHorst_MS (Expert):
Q: Coming from VB6, my debugging technique has been to add On Error Resume Next in each procedure so that even if a command in the procedure produces an error, the user can still continue and attempt to save any work etc. Now in .NET with the (continued)
A: Try-Catch-Finally is the recommended error handling technique for VS.NET, and is what I would personally recommend as well. We mainly include support for On Error for backward compatibility.
Andy Q (Moderator):
For those new to the chat - Our topic is Debugging VB.NET Applications. To submit a question make sure you select the "submit a question" radio button. Thanks
WHorst_MS (Expert):
Q: What is the equivalent of a VB stop statement in C#?
A: System.Diagnostics.Debugger.Break() does the same thing in both languages.
ScottNo (Moderator):
Q: Is this a asp.net debugger config I'm not setting or something ?
A: I don't think this is a setting. Have you tried turning off "Allow property evaluation in variables windows" in Tools->Options->Debugging->General. Your variables windows may be evaluating something every step which takes a long time.
LisaFeig (Expert):
Q: Why is it not possible to set the next statement to a line of code in a Finally block from a brake point in the main body of of a loop see code sample eg if i hit the brake point there is no way of stoping the remaining items in the loop executing. Try
For Each Item As MyCustomClass In eg.Items
' some code with brake point i want to not exec remainder of the loop
Next ' There i no line between end next and funally that i can set as next statement to jump out of the loop early !
Finally
If Not eg Is Nothing Then eg = Nothing ' Get an error if you try and set a line out side of main try block to the next line
End Try
A: Can you set Next Statement to the first line of execution in your Finally block, and achieve the same result? Also, what version are you using?
ScottNo (Moderator):
Q: Somebody had a problem in the vb newsgroup. He had set "when the exception is thrown" to break into the debugger. Than there was an index exception showed. When not there was only a short delay. What does that mean and what would be the action?
A: Let me see if I understand your question fully. Someone set "break when an exception is thrown" and there was a significant delay when the exception occurred. But when this setting was off there was no delay. Is this correct?
ScottNo (Moderator):
Q: No I had not tried that thanks a lot, I give that a shot
A: Let me know how that works out for you. You can reach me at my blog: https://blogs.msdn.com /scottno
DVerma_MS (Expert):
Q: I am writing a windowsapp and compiling with F5 with a bp set. If it executes b4 the code, I get the error. Otherwise the code works fine. Code added. BP on i=. That works, F8 gives error for next line Private Sub RelocateStuff()
Dim i As Integer
Dim j As Integer
i = Form.ActiveForm.Height
j = Form.ActiveForm.Width
A: Okay, I have figured out what is going on here. Form.ActiveForm is a property that gets you the active winform object. When you launch, your VB App's window comes up which is detected by Form.ActiveForm, and so you can calculate Form.ActiveForm.Height.
Once you break into devenv, though, the winform is no longer the active form. In fact the active window is devenv's, which is not a winform window. Hence Form.ACtiveForm returns null, hence Form.ActiveForm.Height throws an exception.
You should change your code to Me.Height, this will return the heiht of the form whether it is the active form or not!
Hope this answers your question.
WHorst_MS (Expert):
Q: Sorry, my quesiton was for VB in VS2005. :)
A: Ron, I think Lisa was answering for VB in VS2005. In VB, you should be able to add private methods and members, local variables, and almost all types of statements within a method, but cannot do things like add Classes, change specifiers (e.g. change Public to Friend), add/edit/delete non-private members/methods, remove private members/methods, or anything that will change the public interface of a type. These edits are considered "rude" and you should get a message telling you to either revert the changes or restart debugging.
WHorst_MS (Expert):
Q: when you delete anything has it gone from your computer completely
A: Could you be more specific? What are you deleting and how?
DVerma_MS (Expert):
Q: Does anyone know how to automate DbgCLR.exe debugger so that I can pass a sourcefile path and a exepath to it at startup. Very anoying that it doesn't have more advanced commandline parameters.
A: Hi!
In order to load an exe into DbgClr, you can launch dbgclr with the name of the exe e.g. DbgClr D:\Windows\notepad.exe. This will load notepad as the debuggee.
You are right that there are no command line arguments to open a file.
If you want to automate this, you need to grab the window for DbgClr when it comes up (say using the title), and using HWND or AA properties you can pass it commands to open/close a file, open an exe and so on. This is not a trivial problem but typically people do not automate the DbgClr.
DVerma_MS (Expert):
Q: reference not set to an instance of an object” error ONLY after I have executed a Breakpoint in debugger. Then ‘Stepping’ through or ‘Continue’ execution gives me the error. I'm using: MS Development Environment 2003, V 7.1.3088 MS .NET Framework 1.1,
A: This is the same as questions (1) & (12)
Andy Q (Moderator):
For those new to the chat - Our topic is Debugging VB.NET Applications. We’re about halfway in, so keep those questions coming!
DVerma_MS (Expert):
Q: reference not set to an instance of an object” error ONLY after I have executed a Breakpoint in debugger. Then ‘Stepping’ through or ‘Continue’ execution gives me the error. I'm using: MS Development Environment 2003, V 7.1.3088 MS .NET Framework 1.1,
A: I mean, this is the activeform question and has been answered. Sorry for the ambiguity!
LisaFeig (Expert):
Q: In regards to Try-Catch-Finally, do you recommend at least one of these blocks in each procedure (to capture all errors), or perhaps a catch-all in the Main() procedure, both, or something else? My concern is capturing unhandled errors.
A: In general, the Exception handling pattern you use depends a lot on the context. Here are some general guidelines:
- Whenever a local resource is being used, the Try/Finally or Using construct should be used to ensure that the resource(s) is disposed of properly
- If you can recover from the exception gracefully, use Try/Catch and do so. (This is rarely the case).
- If you cannot recover from the exception gracefully and in a meaningful manner, bubble the Exception back up to the caller.
- When developing an application, it’s best to handle the UnhandledException event (My.Application.UnhandledExceptionEvent or System.Windows.Forms.UnhandledException) rather than wrap the Sub Main in a Try/Catch. The reasoning here is that there is no easy way to recover from an exception in the catch block of a sub main, whereas the Unhandledexception Event enables you to re-enter the message loop and attempt to recover gracefully.- Generally, you never want to explicitly rethrow exception (e.g., Try…
LisaFeig (Expert):
Continuing my last answer... The last guideline I was trying to say was: Generally, you never want to explicitly rethrow exception (e.g., Try Catch ex As Exception : Throw ex ), as the StackTrace for the exception is reset and it is very hard to debug the error.
ScottNo (Moderator):
Q: What profiling tools are available? Which do you guys recommend?
A: There are many available (just do a search), but there are a few you can try here. I don't really have any specific recommendations.
Andy Q (Moderator):
we have about 15 minutes left in today's chat. Thanks for joining!
LisaFeig (Expert):
Q: Im using vb.net 1.1 - the next statement is part of the main try block body i want to step out of the loop during debug but if the Next is the last statement before the Finallly i don't have a line to "Set as next statement"
A: Yes, you have identified the behavior. In order to leave a Try block, you must execute its last line. I can see how this would be annoying in the particular example you have listed (since you've have to loop through the whole "for" statement). The best thing I can think to do would be to add another line below the "for" statement, within the Try block, and set next statement there.
ScottNo (Moderator):
Q: Scottno, (Cor) you asked me a question, and I gave an explanation, did you understand that ?
A: Yes, I understood perfectly. It looks like an issue several people have had with exceptions in Visual Studio 2003. I know very little about the problem - the best things you can do about it at this point are:
1) Call PSS to see if they have any more information about or a hotfix for this problem and
2) Try out a prerelease of Visual Studio 2005 and make sure that the problem you're having now has been fixed. Otherwise, file a bug at the MSDN Product Feedback Center.
Sorry for the inconvenience this problem has caused you.
DVerma_MS (Expert):
Q: Talking in regards of Windows Server 2003, IIS 6 what is the effect of using remote debugging on the server (VS.NET 2003 EA), will it affect the server performance?
A: Hi! It is not completely clear what you refer to as "server performance" and what kind of remote debugging you are performing.
Simply launching the remote debugger should not make a difference to the perf of the server in that your existing apps should continue to work fine, it is just one extra small process for the CPU.
When you debug simple apps like C#/VB console apps, again the perf hit should be simply of debugging which should be quite small.
Since you mentioned IIS6 I presume you want to do web service debugging. Here, on Win SRV 2003 you attach to w3wp.exe to debug web services. The act of attaching means that w3wp is running under the debugger and there will be a perf hit in processing new requests from clients, like what you see running exe's inside and outside the debugger.
The important scenario is when you break into the process. At that point the process is halted and so you will not be able to process any more requests from other machines until execution of w3wp.exe is continued.
Andy Q (Moderator):
We have 5 minutes left! Time for that last question.
ScottNo (Moderator):
Q: Is there a way to get the ability to view items in a collection in the watch window using vs2003 maybe an add-in ? ( i know this is all VERY nicely imporved in vs2005 but the powers that will not let me use that for work for a long time :) )
A: If you want to solve this via an Add-In, you'd probably have to reimplement the functionality of the watch windows, etc. Your best bet is to take a look in this directory \Common7\Packages\Debugger and find the *.dat files. If you're using Managed C++, C#, or J#, you can use these *.dat files to customize views in debugger variables windows. The files are unsupported and undocumented, but are somewhat self-documenting. Try it out! Unfortunately, as far as I know VB lacks these capabilities.
ScottNo (Moderator):
Q: Can you point me to an example that shows how to consolidate tracing to one centralized event log,from multiple computers running the same program on a LAN?
A: Try out the Enterprise Instrumentation Framework here: https://www.microsoft.com/downloads/details.aspx?FamilyId=80DF04BC-267D-4919-8BB4-1F84B7EB1368&displaylang;=en It's a very robust logging system, and it comes with lots of samples.
Andy Q (Moderator):
2 minute warning!
ScottNo (Moderator):
Q: ScottNo - Thanks. That is one I hadn't found.
A: You're very welcome. Glad to help.
LisaFeig (Expert):
Q: How come VB still seems like the poor cousin?
A: Can you tell us, more specifically please, what is making you feel that way?
DVerma_MS (Expert):
Q: in the above case where in dtCurrent.ToString() is unable to retrieve the value, I could successfully retrieve the values of other variables. How is it possible?
A: Hi Azhagan, I need more info to track this issue. What kind of an app do you have? It is a VB Console multithreaded app? In that case, is dtCurrent a local variable to one of the thread functions?
LisaFeig (Expert):
Q: Ok, seeing that we have had our 2 min warning I would like to say thank you to all the experts
A: Thanks for attending. It was great to hear all your questions and comments :).
DVerma_MS (Expert):
Q: in the above case where in dtCurrent.ToString() is unable to retrieve the value, I could successfully retrieve the values of other variables. How is it possible?
A: I will follow up with you on this offline. Thanks!
ScottNo (Moderator):
Q: Hello. When I go to server explorer, and try to debug a stored procedure, I am not getting the debug option in my context menu. Is this suppose to be an option?
A: I'm not sure - I'll need to know a bit more about your setup. Let's talk over email - you can contact me from my blog: https://blogs.msdn.com /scottno
Andy Q (Moderator):
I'd like to thank our experts and guests for their participation today! Please look for upcoming chats at https://msdn.microso ft.com/chats/
ScottNo (Moderator):
Q: Do you know of a tutorial that will show - step by step - how to configure cross tire debugging from my win forms UI through web service data access provider and into the TSQL code of my SP - it's the TSQL debugging that i am mainly having issues !
A: Let's continue this offline: https://blogs.msdn.com /scottno
DVerma_MS (Expert):
Bye! You can access my blog.
ScottNo (Moderator):
Thanks everyone, it was fun. If you have any more debugging questions, feel free to send me mail through my blog: https://blogs.msdn.com /scottno
Andy Q (Moderator):
Bye
![]() |
Top of Page |