VB project doesn't enter in debug mode after change to release and back to debug - vb.net

I have a project in VB VS2003 everything work fine until i change it to Release, compile and then back to Debug. Now i can run the project but it doesn't stop on any breakpoint, i had try on different machine and the result is the same, i have try with other project and everything work fine
<STAThread()> _
Public Shared Sub Main()
Dim splashWin As New Splash 'Here is one breakpoint and it never stop
splashWin.Show()
Application.DoEvents()
Note: If I press the break all(pause) button on VS it launch this error: "Unable to break execution. Please wait until the debuggee has finished loading, and try again." But the application is running fine

Related

Unhandled win32 exception occured in the application

I have an application in vb.net that I'm testing out in Windows 10 and I seem to be getting an error (Images below). This app works flawlessly in Windows 7, and it actually works without any issues in Windows 10, the problem is, when I exit the application is when I get the error.
The way it's structured, is if I run it from IDE, i first see a Login Windows where user logs in and then goes to MENU. If it's run in our environment, user does not have to log in, so the log in form never appears, it goes directly to MENU.
Everything works great, until I go to EXIT Application, where it gets all messy, this is the code from EXIT button...
Dim Answer as Integer
Answer = MsgBox("Are you sure you wish to Close the application ?", MsgBoxStyle.YesNo)
If answer = vbYes Then
End
End If
These are the errors I get:
First I get this error, clicking on CLOSE PROGRAM closes it completely, if I click debug I get the below windows....
With the 2nd error it shows that I actually have VS2010 and VS2012, and it lets me debug. The issue is, the source code is in TFS, and it just so happens that I can't access the TFS from my windows 10 machine, (only from Win 7). So I can't debug it. But is there a reason why this is happening only in windows 10?
I even went as far as doing Me.Close() before END to make srue that the form is closed. And again, it works fine in Win 7, but win 10 it gives me the same problems.
Using "End" to close a program can be problematic; the comments and answer to this SO question explain why that is. As for the second issue that popped up once using Application.Exit(), that is a simple case of your program referencing multiple assemblies that have function calls with the same name. In this case, both the explicitly imported Microsoft.Office.Interop.Excel and implicitly imported System.Windows.Forms have "Application.Exit()" members. Since you have explicitly imported Excel, the compiler goes with that one when it's forced to decide which Exit() to use, which throws an error because of the context it's being used and doesn't actually close the program. To rectify that, all you have to do is explicitly tell the compiler which Exit() you want to use by replacing
Application.Exit()
with
System.Windows.Forms.Application.Exit()

Console won't open when launching console application on startup VB.NET

I have a console application that I can't seem to make launch properly on system startup.
I've debugged it by putting together a really simple console application that's simply just
Sub Main()
Console.WriteLine("This is a console application")
Console.ReadLine()
Environment.Exit(0)
End Sub
And even that won't work. The application is launching, I can see it in the task list. But the console interface isn't displaying, and that's the problem.
I've tried both using the Start Up folder and Windows Task Scheduler to get it to come up, neither seem to work.
Is there some registry setting somewhere I might change?
Any help would be awesome.
Thanks.
According to Microsoft, the task will only run interactively if the "Run only when user is logged in" radio button is selected.
"You can specify that a task should run even if the account under which the task is scheduled to run is not logged on when the task is triggered. To do this, select the radio button labeled Run whether user is logged on or not . If this radio button is selected, tasks will not run interactively. To make a task run interactively, select the Run only when user is logged on radio button."
Source: https://technet.microsoft.com/en-us/library/cc722152.aspx?f=255&MSPPError=-2147217396

WeifenLuo DockPanel Suite Form Freeze on Close

recently I decided to implement the WeifenLuo DockPanel Suite into my VB.NET application. Everything works fine, until you try and close the application, where it then freezes. Nothing happens.
I tried:
Disposing of the DockPanel before closing
Using Application.Exit()
RunningApplication.DoEvents() before closing
Closing any open DockPanel forms before closing.
Running the application outside of the Visual Studio Debugger.
Setting Visual Studio to target x86 instead of AnyCPU
Upgrading/Downloading the DockPanel Suite framework version
Yet still nothing,t still simply freezes.
The output shows the following messages:
The thread 0x1f34 has exited with code 259 (0x103).
The thread 0x22b8 has exited with code 259 (0x103).
With the thread names being different each time. However I don't have any threads running.
This only occurs on the form with the DockPanel.
Any thoughts? I can't find anyone else with this issue online, and it is really frustrating.
Thanks.
In the form closing event of my application, I iterated through any open documents in the DockPanel using:
While i < DockPanel1.ActiveDocumentPane.Contents.Count
Dim dockContent As IDockContent = DockPanel1.ActiveDocumentPane.Contents(i)
dockContent.DockHandler.Close()
End While
This is what was causing the application to freeze. To fix this, I replaced the code with this:
For Each item As DockContent In DockPanel1.Documents
item.DockHandler.Close()
Next

VB.NET: Stop smoothly in debug.assert (false) line

I always write code like this:
If SomethingIsTrue Then
'DoThis
ElseIf SomeOtherThingIsTrue Then
'DoThat
Else
Debug.Assert (False)'Doh!! I forgot to handle a certain condition
End If
In VB6 this worked great. During testing my app in the IDE, it just stopped in the Debug.Assert(False) line, and I saw where I missed something.
But VB.NET does not stop there but instead gives me a huge messagebox. This seems to be standard behaviour for Debug.Assert.
I have 2 questions, please:
1) How can I make it stop smoothly in that line instead of showing the messagebox?
2) How can I make it so that at runtime (!) no messagebox is shown but instead my application just keeps running without stopping or showing a messagebox?
Thank you!
I would write something along this line:
if debugger.isattached=True then
debugger.break
end if
Just wrap it in a shared sub, and you can simply call it in the else statement.
The code is typed without visual studio at hand, so I hope it will work.
How can I make it stop smoothly in that line instead of showing the messagebox?
Just click Retry on the message box that pops up. From MSDN:
Clicking Retry sends you to the code in the debugger if your application is running in a debugger, or offers to open a debugger if it is not.
Clicking Ignore will, well, ignore the message.
How can I make it so that at runtime (!) no messagebox is shown but instead my application just keeps running without stopping or showing a messagebox?
I don't mean what you mean with at runtime, since all asserts happen while your code is running, hence at runtime.
If you mean that asserts should be ignored while running your application without a debugger, just make a release build instead of a debug build. The Debug.Assert method works only in debug builds, and the point of debug builds is that they are easy to debug.
If you want nonetheless suppress the message box, see Customizing Assert behavior:
For example, you could override the TraceListener.Fail method to write to an event log instead of displaying the Assertion Failed dialog box.
To customize the output in this way, your program must contain a listener, and you must inherit from TraceListener and override its TraceListener.Fail method.

VB.NET Process.Start() immediately stops

I'm having a strange problem with the following code, I'm writing a game launcher in VB.NET:
Dim gameProcess As Process = New Process()
gameProcess.StartInfo.UseShellExecute = False
gameProcess.StartInfo.FileName = TextBox2.Text
gameProcess.Start()
Debug.Print("Game started")
gameProcess.WaitForExit()
Debug.Print("Game stopped")
This code is working fine with most programs, but with some of them (Age of Empires e.g.), I get the following:
Game started
Game stopped
I see the game running for a split second in the task manager, but it immediately closes! Does anyone know why? When I run the game from Windows, it works fine.
I've also tried with Shell, same problem.
And I've tried with cmd.exe and the /C argument, same problem (note that when I type cmd.exe /C path_to_game_exe in the Windows Run Dialog, the game also starts fine), it's only when I launch it from the VB.NET app that it gives problems.
My last idea was to write a temporary batch file and starting that one, but that seems like an ugly solution.
Another option you can try: set the working directory property in the startinfo. You can find this info by looking at the properties of the games' shortcut in your startmenu.
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.workingdirectory.aspx
A lot of games use a launcher app that starts the game in separate process and then closes.
It could be the copy protection that detects the debugger on your system and exits the process.
Try compiling the game in Release mode and run your application when Visual Studio is not running.