Run VB.NET application is silent for distribution - vb.net

I have created an application that installs and edits configuration settings for a 3rd party application. The application works fine but I need to prepare it for deployment, which means I need to edit it so that it can run silently. I've created it in Visual Studio 2012, if that makes any difference. It contains 3 Messagebox.Show for errors, that I suppose I should output to the error log, and the "Configuration Complete" prompt after success. There is a single button click to start the configuration function.
I have looked around and found only people trying to silently run other applications silently from within their code. If anyone can point me in the right direction I would be grateful.

Just add a Module to your project.
Change your Startup Object to "Sub Main" in Project Properties>Application Tab
Then add a Sub Main your module:
Module Module1
Sub Main()
'call your program code here instead of from your button click
End Sub
End Module
And yes you need to log your errors to a file instead of showing them in a Message Box

Related

Application.Designer.vb file is duplicated when change startup form for VBNET

I have a VBNet project in Visual Studio 2019, today I face this issue suddenly:
When I change the startup form (which I did million times before without errors) to another form, the file Application.Designer.vb is duplicated with new name Application1.Designer.vb
This file leads to build error: 'Protected Overrides Sub OnCreateMainForm()' has multiple definitions with identical signatures.
If I try to remove file Application1.Designer.vb then File Not Found error will be thrown.
If I remove the compile tag for Application1.Designer.vb in the project vbproj file then build fails but no error is shown.
I could mess up with the app settings but I am now completely stuck and have no idea to run my project since these are all auto generated.
Please suggest anything that I should check. Thanks all!

AccessViolationException when typing in Textbox

About a week ago a program I'm working on began crashing with an AccessViolationException whenever I typed into a certain textbox. I've reduced it to this test case, but I'm out of ideas:
Imports System.Windows.Forms
Public Class Start
Inherits System.Windows.Forms.Form
<STAThread()>
Public Shared Sub Main(args() As String)
Application.EnableVisualStyles()
Application.Run(New Start())
End Sub
Private txtNotes As System.Windows.Forms.TextBox
Public Sub New()
Me.txtNotes = New System.Windows.Forms.TextBox()
Me.txtNotes.Multiline = True
Me.Controls.Add(Me.txtNotes)
End Sub
End Class
When I build this program using Visual Studio, it crashes if I type into the textbox (always). If I build it using vbc.exe Start.vb /target:winexe /main:Start /out:Start.exe, it works fine.
Additionally, I've found that removing either of these lines stops it from crashing using Visual Studio:
Application.EnableVisualStyles()
Me.txtNotes.Multiline = True
I've already done a repair installation of Visual Studio, and used sfc.exe to check for corrupted system files. I've tried searching for existing solutions to this problem, but haven't found anything. What could be causing Visual Studio to build a broken executable? Is there some setting that would do this?
Edit: I'm also running AVG antivirus at the moment. I recall that there was an AVG update around the time these crashes began. As per one of the comments below, disabling AVG, and then scanning the executable prevents it from crashing. This would seem to indicate that the problem lies with AVG.
We have the same problem with a few of our clients' installations on Windows 7. Our product is C# with WinFoms and .net 4.0. Typing in a mutli-line text box under WinForms crashes an AccessViolationException. You can paste text in the box and delete it too, just not type. Single line text boxes are fine. We also found that removing Application.EnableVisualStyles() cured the problem.
Another way to fix it without code changes is to right click the program icon and change the compatibility settings to run the program for Windows 7.
I'm having the same problem, and I'm running AVG too.
As a temporary solution before AVG provides a fix, you can add the .exe file to AVG's list of exceptions. I can confirm that this removes the AccessViolationException shown in Visual Studio.
Open AVG, go to Options
"Advanced settings..."
Exceptions
"Add exception"
Choose "Application or File"
Select your executable file (in my case, I used .../bin/Debug/myexe.exe)
I checked "Even when the file has been changed or updated"
Finally, I checked all of the three options at the bottom: "Resident Shield", "Manual and Scheduled Scan", and "Identity Protection"
I did not perform any change regarding visual styles or compatibility mode, as mentioned in other answers.
I had the same problem. Solved it by unchecking Enable XP visual styles.
Some background in case it helps anyone else. Application was originally created in VS2010. Moved up to VS2015RC. Everything worked fine. Problem occurred after a reinstall of the OS (Win7). Even the old version of the application would not work, although it did continue to work on all the other Win7 desktops, including a new install. If anyone knows why, it would be interesting.

Why doesn't Visual Studio debug my VB.NET application?

I recently have encountered a weird issue with my project: as soon as I click debug and it builds the project, it stops debugging. There isn't any error message, or anything else that comes up, including the form itself.
I've tried messing with the settings: no splash screen and I've even changed the startup form to a blank Windows form. What could be causing this problem? Is it Visual Studio or my code?
Probably your program is exiting normally. Set a breakpoint at the first statement to be executed, press F5, then single-step through the program until you get to the last statement executed.
If the first statement is never reached, then one of two things probably happened:
You're mistaken about which statement is executed first, or
The program is terminating during initialization, probably because a class constructor is exiting the program either normally or abnormally.
A few ideas:
Use Debug->Exceptions, and check all the checkboxes so you break when an exception is thrown.
Use Debug->Step into to step into your code.
Then you can use Step Over and Step Into (look at the menu for the keyboard shortcuts)
I found a solution, but not the problem.
How I fixed it:
I just created a template for each form, created a new project, and imported everything into the new project. One thing that I found useful is in the new project is to add an existing item (CTRL + D), and group select (maybe, don't know if you can) and select all the non-code/form/designer/etc. files (like text files or images) and then import them.
I have found a possible solution after I had the same problem.
You probably have more than one project in your solution (The main project, plus an "InstallShield" project",perhaps)
Make sure you have the main project set up as "Startup Project".
In the Solution Explorer, right click on the Main Project and select "Set as Startup Project".
Everything will then run OK.
If you get the error like: "The debug mode is program but there is no program specified....." Go to Solution Explorer then Right Click on main project's name and Click on Set as StartUp project. You can debug your program.

Windows XP Excel VBA Crashes on Windows 7

I am trying to switch a Excel VBA macro from Windows XP to Windows 7. Both of the Windows versions are 32-bit operating systems. My Windows 7 version is Enterprise edition.
The VBA code works fine on Windows XP. When I have tried to run the code on Windows 7, it crashes and reports no error description.
I have registered msinet.ocx, which appears to be required for Microsoft Internet Transfer Control 6.0. I have also tried to fix security issues by adding the additional com components tabctl32, comctl332/232/32 and comdlg32, all of which are ocx files. However, nothing changes - my code still fails on Windows 7.
Once msinet was unregistered, Excel VBA opens my Workbook, reports the missing reference msinet and does not work at all. How do I resolve this issue?
Awkward. Open the sheet in an Excel session with Macro Security set to high or medium, and reply 'No' to the dialogue about enabling VBA macros in the sheet.
If it opens, you should still be able to view the project, and this might show an obvious missing reference or an error if you attempt to compile it.
Next: save the workbook as html and close Excel. Clear the temp folder, restart excel, open the html file and save it back into Excel format. If you're lucky, all the legacy objects and references will be cleared out and replaced by versions compatible with your new OS.
This works about half the time.
The system not crashing when msinet.ocx is not registered doesnt necessary means that it is the problem.
If you have a call to that library (msinet.ocx) in any procedure inside of or called from the ThisWorkbook module and you have that library unregistered, then when the file opens and tries to run the On open macro the module will not compile and therefore wont run the line of code that makes it crash. (I am only guessing that this might be your case.)
Try to find out which exact call makes your system crash.
Let msinet.ocx registered.
Open the file without activating the macros.
Then manually run Step by Step (F8) through the opening code of your file ( Private Sub Workbook_Open() )
Eventually you will reach the exact line of code that makes your system crash. Whit that information you will be able to get more help.
NOTE:
To open the file without activating the macros you can use one of the following methods:
Press and keep pressed the Shift key after you doubleclicked on the file to open it(from the windows explorer). For this method to work, the Excel application must be clossed.
If the Excel application is open, then go to the VB editor and type application.EnableEvents=False in the immediate window (and press enter to run it). Just be aware that this will disable the events on every file in that instance of Excel. You will have to set it back to true or close the application (not just the file).
Check if you don't have references to missing libraries, if so simply uncheck it. I had a similar problem and it helped in my case.

Weird debugging situation: "There is no source code available for the current location"

I have a Windows Forms application in a single project written in VB.NET 2003 (legacy code). There is a MainForm and a SecondaryForm that is run by the MainForm. When I run the application through the MainForm, I can debug without any problems.
However, if I just run the SecondaryForm, I get the debug error:
There is no source code available for the current location
when stepping over:
_routeId = CInt(myVar)
At this point I am no longer able to debug through my code window, but I have to use the disassembled code.
Why does this happen and how can I fix it?
My problem was of the Step-Into kind. I could step into a procedure inside a usercontrol just fine, but when its End Sub was encountered and I was leaving that Sub, I would get the "There is no source code available for the current location." error page.
The solution that personally worked for me was: In the Project Properties page, under "Debug", uncheck "Enable unmanaged code debugging".
I have seen this issue many times... and more often than not it is a reference(s) issue. Is it your code that has "no source" or is it Microsoft code? Do you have multiple versions of the .NET Framework installed?
Double check your references.