How to resolve phantom breakpoint? - vb.net

When I start a debug session, program execution halts at a line that appears to be breakpoint (yellow background color). I must press F5 to continue, and the program proceeds normally.
I call it a phantom breakpoint because no breakpoint appears to be set, and even though executions stops within a loop, I need only press F5 once to proceed.
I tried setting a breakpoint at the phantom location, and removing all breakpoints but to no avail.
The only other similar problems I can find are for Java, and MS-Access where the solution was to de-compile the application.
Although this is very annoying while in development, I was gritting my teeth and baring it until the application was installed on a Citrix server where an error message box is displayed saying that a breakpoint had been encountered.
As an afterthought, I just rebuilt the setup program and after running the application, a critical error was issued. In debug mode, the message was "myapp.exe has triggered a breakpoint:". I cannot explain why it works at all on the Citrix server).
I sure would appreciate any suggestions on how to resolve this issue.
TIA

You are running somebody else's code and that code has an explicit debugger break instruction compiled into the program. You can do so for example by writing Debugger.Break() in a managed program. It could also exist in unmanaged code, the __debugbreak() intrinsic or the DebugBreak() winapi function do this. Could be a simple oversight, it could be that it was intentionally left in the code to warn about a problem.
One way to find the programmer that did this is by using the debugger. Project + Properties, Debug tab, tick the "Enable unmanaged code debugging" option. Then Tools + Options, Debugging, General, untick the "Enable Just My Code" option.
Run the program and reproduce the condition. Now use Debug + Windows + Call Stack and look at the very top of the list. Scroll up if necessary. It might well be grayed out to indicate that this is not your code, it won't be. You'll see the name of a DLL there. Call the company or programmer that wrote that DLL and ask for advice.

Related

Why does my VBA procedure sometimes stop in debug mode?

I have a button click event in an Access form that sometimes opens the VBA editor with the 'On Error...' line highlighted as if it is in debug mode. I can F5 to continue the rest of the procedure and it works fine.
It doesn't happen everytime. It seems random except there seems to be a pattern that it happens on the first click of this button right after the file is opened. Not everytime though.
Any thoughts on this or previous experience with the same thing happening and subsequent solution? What might be causing this? It's a terrible user experience.
Well, before running any code (hold down shift key during startup to prevent any code from running).
Now, ctrl-g (jump to VBA IDE). Now from tools. Choose
debug->Clear all Breakpoints
Like this:
Now, open up any code module - hit enter key to "dirty" the code. Now choose debug->Compile (first menu option). It will say Compile "my app name".
Make sure the code compiles. If it does not, then stray break points can still exist.
Next up, you need to check/change the default behavior for a error.
While STILL in VBA editor/IDE
From menu bar choose tools->options. The default is "Break on Unhandled errors"
If you have break on ALL Errors? Well then code that even assumed to trap or even on-error resume next code it BLOW UP and stop. Often developers will say try for existence in a collection, and we error tap to "mean" the element is not in that list. However, the THIS assumes that the default Error trapping setting was not change.
So, double, and then triple check this setting. You can develop for years, and even have some code ASSUME to error out. But that years of development code assumed the default (break on unhandled Errors. If you have break on all errors, then your are toast, and you find all kinds of breaking of code. (the idea of that option is to LET you debug code with error handling without having to disable errors. And with say on-error resume next, you in effect can't debug parts of code anymore.
Now, if above steps don't fix your issues?
Then the next step is to de-compile your application. This will remove the compiled (binary) part of the application. Once you do this, then you do a full re-compile.
To de-compile, you can't do this from the IDE, and you have to use a FULL qualified path to your existing version of access. Say like this:
"C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE"
"c:\MyCoolApp\Invoice.accDB" /decompile
Now, when you run above, you REALLY must not let any startup forms or code run. (hold down shift key. Now exit access/application. Now re-launch (and again no code to run on startup).
Now, at this point I high recommend a Compact+ Repair (and AGAIN no startup or code to run). So even on the C+R, you have to hold down shift key.
If you during the decomp, start application, then C+R allow ANY code to run, then you have to start over again at the first decompile step.
Ok, now you done the C+R. Now ctrl-g, and now debug-compile.

VB.NET Strange output message "Uninit : Still Alive 1"

I run my program in DebugMode and then quit it by closing the main form.
In the output window I can see the following message:
Uninit : Still Alive 1The program "[1432] App1.exe: Managed (v4.0.30319)" was ended with code 0 (0x0).
I wonder what the "Uninit : Still Alive 1" means.
Does anybody know???
I am always really scared of something unexpected occuring at some point of time, and the message "Still Alive" does not really sound promising to me.
Thank you for the help!
It is a diagnostic message that was generated with OutputDebugString(). It is present in one of the DLLs that you have a dependency on. The exact meaning requires interpretation, but "Uninit" is short for "Uninitialize", the kind of thing that happens when a DLL gets unloaded. And "Still Alive 1" would probably mean that the programmer of the DLL is miffed about you not properly shutting down his component before you jerked the floor mat.
The message is missing a line-break ("\n"), a pretty standard mistake that programmers make when they use OutputDebugString.
Two basic ways to find the DLL that does this. First one is to turn on unmanaged debugging with Project + Properties, Debug tab, tick the "Enable native code debugging" checkbox. The DLL unload notification should be close to the diagnostic message.
More reliable is using SysInternals' Process Explorer. Select your process and press Ctrl+D to list the DLLs it has loaded. Given the quality of the message, you can probably skip the ones that have a Microsoft copyright. Right-click the DLLs one-by-one and look at the "Strings" tab to see the strings inside the DLL. Once you find it, you should know who owns that code from the DLL name. Ask them how to shut down properly.

VB Code does not stop at breakpoints

So, I am writing a Office 2010 Add-In. I have the code working and running, but would like to step through a section of code. I've added the break point and hit debug. Word starts up with the add-in loaded. This what I see in the debug window:
'WINWORD.EXE' (Managed (v4.0.30319)): Loaded
'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
The program '[3280] WINWORD.EXE: Managed (v4.0.30319)' has exited with
code -1073740791 (0xc0000409).
I can interact with the add-in (Custom Ribbon), but the code never stops on the break point. I've been scouring the web and trying multiple things, but can't seem to get it to work.
Thoughts?
I don't know why it thinks the process has ended--I've never worked with debugging Office add-in's--but, in case their's no other option, you can always resort to adding a Debugger.Break() call to your code. That will force the process, when it hits that line, to bring up your debugger and let you trace through the already running process. You have to be careful to remove the line, though, before you compile a release version of your assembly.

Visual Studio 2010 debugger is no longer stopping at errors

I was working on a Windows app today, when my errors were no longer being displayed as they usually would. Instead, the debugger just jumps out of the method. The output window makes a note of the exception, but the usual popup trace does not appear.
It works in other projects, and I have put Dim i as Integer = "A" as my first line to try and raise an error, but it just exits the sub on that line.
Any ideas how I get it back?
There is a bug in the interaction between the debugger and the 64-bit version of Windows 7 that strikes in the Load event. An exception is trapped and swallowed by Windows, the debugger never gets a chance to detect that it was unhandled. The only thing you'll see is a "first chance" notification in the Output window. The Load event handler will immediately terminate and your program keeps running as though nothing happened, assuming that it didn't bypass a critical piece of initialization code. This bug has been around for a long time and is well known to Microsoft, apparently it is difficult to fix.
You can work around this bug with Project + Properties, Compile tab, scroll down, Advanced Compile Options button. Change the Target CPU setting to "AnyCPU". Another way to trap it is with Debug + Exceptions, tick the Thrown checkbox on CLR Exceptions. Yet another workaround is to put initialization code in the constructor instead of OnLoad() or the Load event. You only really need Load when you need to know the actual size of the window.
This bug will only strike when you debug. It won't happen on your user's machine.
UPDATE: I expanded a great deal on this mishap in this post.
Under the Debug->Exceptions check that the Common Language Runtime exceptions are checked.
Has your .suo file been deleted by any chance (this is the file that stores your personal state of the solution, your settings, what is expanded / collapsed). You will only really spot this if you suddenly noticed that you had to hit "collapse all" because it had forgotten, it will recreate this when you open the solution, but will do it with default settings.
If so, hit CTRL + ALT + E and re-tick the break on exceptions tick boxes for CLR exceptions.

Showing DialogBox and MessageBox from DLL

I'm buisy on a DirectX10 game engine and i'm having a problem which has nothing to do with DirectX :P The problem is that in the DLL which contains the engine sometimes a DialogBox is called, just like you would do in normal win32. With the only difference that instead of the HINSTANCE i use the HMODULE which i get when loading the DLL.
Everything seems to be working fine, if i step through my code with F10 (Visual C++ 2008) i can even see it going through my DlgMessageProc function and do everything it should do. The only weird thing is that no dialog is shown and that all of a sudden it jumps out of the message loop and just continues with the rest of the code???
Weirly engough I have the same problem when calling MessageBox from inside my DLL, I get no errors, everything seems to be working fine but no window is shown, nor is the code halted (as normal with messageboxes)
The funny thing is that I have some code from a book which uses the same basic architecture as me and if i compile that everything shows just fine??
So my question, is there any hidden option, pragama comment or other thing i should look at if i want to be able to show MessageBoxes and Dialogs from my Dll?
No as i thought, chaning the manifest doesn't help at all. I also created a separate project where i just test the dialog and its proc function and there everything works perfect (links to a .exe instead of dll)
In the visual studio resource editor's property page for the dialog resource there should be an option in which you can specify - "No Fail Create: True".
Usually dialogs fail to create because a common control cannot be created - usually because InitCommonControlsEx has not been called. Setting the No Fail Create flag lets you see dialog and determine which controls are missing.
Other things to check:
Is there a message in the debug window about a first chance exception? Perhaps its 'jumping out' because of an exception that is being caught and silently handled by Win32. Turn on debugging of first chance win32 exceptions in the Dev Studio exceptions dialog to track that down.
Even this wouldn't explain how a MessageBox call would fail to create a message box.
The only times Ive seen MessageBox fail to work were when:
Resource leaks had made the process run out of available user32 handles - have you checked your apps handle counts using task manager?
the system was in the process of being shut down. Have you called PostQuitMessage and then tried to create a dialog/MessageBox?