I wrote a Visual Basic program back in VB4 (yes, really!) to track my petrol/gas consumption, and subsequently compiled it in VB6, Visual Studio Express 2010 (I think), VS Express 2015 for desktop, and I'm now trying to compile it in VS 2019 Community, without success.
I made a back-up copy of the source code folders, and pointed VB at the original .sln file. The source all seemed to load up ok, but when I try to run the program in debug mode, the splash screen comes up, but never goes away, and the main form "frmMain" never gets loaded. I set a breakpoint at the first line of code in frmMain:
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
but I get an error "The breakpoint will never be hit. No symbols have been loaded for the current document".
This doesn't mean anything to me, and this message has appeared in the forums for years, seeking explanation, without an agreed common solution. I'm definitely in 'Debug' mode, not 'Release'. I've checked in Properties/Application that frmMain is the Startup form, and the Splash screen is set to frmSplash. Is the 'current document' frmMain? What are 'Symbols'?
Incidentally, I have a lot of 'Messages' which say, eg 'Message IDE1006 Naming rule violation: These words must begin with upper case characters: btnSaveNewCar_Click'. Why is this? It's never arisen before - has something changed in VB?
Related
This might be a case of never noticed OR I have broke something
I have three projects two with multiple forms and one with only one form
Visual Studio 2019 v 16.6.2 with Frame Work 4.7.2 On Windows 7 64 bit
All the projects are WinForms with VB
I have been making a number of changes like Under Compile un-check 32 bit it is back on now
Under Application I changed framework to 4.6.1 It is back to 4.72 now
My Subs do not look to have the correct format to me please I am only 3 weeks into this IDE
I do not see the ByVal and ByRef tabs in any of my Subs in any of the Projects
Private Sub frmOne_Load(sender As Object, e As EventArgs) Handles MyBase.Load<br/>
I have Shutdown Mode set to When Last Form Closes for startup form YES I tested both ways
When I say Shows Project Closed here is what I see (See Screen Shot)
All the projects run as expected
I tested these lines of code on all three project it does not work and I do not understand it so it is deleted
Public Sub SetIcon()
InitializeComponent()
Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetExecutingAssembly().Location)
End Sub
The question is this normal behavior and I have been asleep for 3 weeks?
If this is not normal behavior where do I look or how do I fix this?
That red square is simply the tool button to stop a debugging session. The Debug toolbar is only displayed while you're debugging, so maybe you just haven't looked at the toolbar at that time before. Have a look at the Debug menu in VS while you're debugging your project and while you're not to see the difference. Only options that apply to the current state are displayed.
As I mentioned in a comment, ByVal is the default and is now generally implicit. You can make it explicit if you want but if you have Pretty Listing (auto-formatting) enabled, it will be removed automatically.
InitializeComponent is basically the auto-generated method that creates and configures the controls and components you add in the designer. It must and should only be called in a constructor for that reason.
I'm having this InvalidOperationException
An error occurred creating the form. See Exception.InnerException for
details. The error is: Object reference not set to an instance of an
object.
pointing at this line of code:
Private Sub BeginningBalancesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeginningBalancesToolStripMenuItem.Click
inventory.MdiParent = Me <--error here
inventory.Show()
End Sub
EDIT:
Im only using drag and drop for creating controls from the toolbox. The thing here is, everything works fine until I relocated AND decided to return panel_001 to its previous location by pressing ctrl-z in the inventory.vb during design time to revert the change I made. The program runs fine without error prior to that specific panel relocation. I never edited any codes in the designer.vb and in the inventory class. I strongly believe that a piece of code wasn't properly restored at the ctrl-z action in the inventory.Designer.vb. Is this a visual studio bug?
EDIT: I tried creating a new winform and attempted to start fresh by foolishly copying & pasting all the controls and the forms' class and was no good. I assume the problem does not lie under the striked-out line above.
The Winforms designer has a knack for tripping really mystifying design-time exceptions. A side-effect from its strong WYSIWYG design, it will run some event handlers at design-time. Like Paint, making a control look the way it does at runtime. Nice, but that does come with a price. This can easily cause an exception if such an event handler was not written to operate correctly at design time. You are supposed to use the DesignMode property to keep the code safe.
Coming up with a way a Click event handler could run at design-time however requires massive amounts of imagination. That is an event that will not run at design time, the designer uses a layered window that intercepts any mouse clicks, using them for design use instead. Like selecting a control or displaying the design-time context menu.
I have actually seen the Click event of a ToolStripMenuItem run. The designer is not 100% watertight but it happened just once and I was hacking the code pretty hard. Coming up with a way that it could possibly run by using Undo is going to be difficult. Maybe you give it the Ctrl+Z shortcut, don't assume that guess is credible.
The way to deal with incomprehensible black magic like this is to just dismiss it and move on with your life. You just don't stand much of a chance to diagnose it and if you do then there's nothing you can do about it anyway because this isn't your code. Well, other than the need to use DesignMode, that may well be necessary. Not in this case. The only thing you have to watch out for is that such an exception did not destroy the InitializeComponent() method. That can happen too, you notice by controls being missing when you re-open the designer. Very unpleasant, you do need a good backup copy in source control to recover from that lossage.
OK! after giving it a few more tries, I found the answer. After the exception shows, copy exception details to clipboard and then I pasted it on Notepad. It had a lot of texts but the bottom part was the important one:
--insert wall of texts here-- in C:\Users\Ellen\Documents\Visual Studio
2008\Projects\SampleApplication\SampleApplication\Forms\inventory.Designer.vb:line
760 at CabuyaoWaterDist.inventory..ctor() InnerException:
It pointed me out to the specific line in the designer where the ctrl-z did not properly revert one of the label's caption
I've run into an issue that I just cannot seem to find the answer to anywhere on the internet. I have an application that hosts an Infopath.FormControl inside of a Windows Form. Each of the InfoPath forms have 5 views that they have to display, and using Infragistics UI v11.1 controls, we have each of the views on a separate tab in the application.
The application is able to display the first four views that you choose correctly, and it doesn't matter what order you pick them (eg 1,5,4,2 or 1,2,3,4), but after the the fourth one, it will always come up with the error "COM object that has been separated from its underlying RCW cannot be used."
Private Sub utForm_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles utForm.Click
lastTabClicked = Me.utForm.SelectedTab.Text
Me.OHeader1.Focus()
' If Me.formIsReadOnly Then
If Me.fcInfoPath Is Nothing Or wasPrinted Then
If Not Me.utForm.SelectedTab Is Nothing Then
processReadOnlyTabChange(Me.utForm.SelectedTab.Text)
Exit Sub
End If
End If
'This is the line of code that will get the exception, but by the time we get
'here, the COM object has already been released.
Me.fcInfoPath.XmlForm.CurrentView.ForceUpdate()
'Failed Ideas to stop the Com object from separating from it's wrapper (RCW)
'Dim test As IntPtr = Marshal.GetIUnknownForObject(Me.fcInfoPath)
'Marshal.AddRef(test)
'GC.SuppressFinalize(Me.fcInfoPath)
'SyncLock fcInfoPath for duration of event
If Not Me.utForm.SelectedTab Is Nothing Then
processTabChange(Me.utForm.SelectedTab.Key)
End If
End Sub
I've looked deeper into the code, and it never calls a Marshal.ReleaseComObject or any dispose methods. I also did a GC.SuppressFinalize on the FormControl object, and added a SyncLock around the code that updates the view, in case there was a threading issue. I even manually added hundreds of references to the COM object as a last ditch effort, as the COM object is supposed to be released only after the last reference has been removed. None of these things has had any effect. Always after the fourth view change, it comes up with that error, and following every line of code gets me nowhere. It always loses the COM object sometime between setting the fourth view and hitting the above event. There is no code executing during this time that I know of, so I've become stuck on this issue.
EDIT: I should also add that this is an application being upgraded from .Net 2 to .Net 4, and this worked perfectly before, when it was using InfoPath 2007. Right now, it's using InfoPath 2010 x64 (I did not choose the office version), and I'm thinking it might be possible that the 64-bit version of InfoPath could have some issues that might cause this.
EDIT 2: This is not an issue with the 64-bit version. I switched out my version of Office and recompiled with Office 2010 x86, and I still get the same error as before.
I am not familiar with the COM interface to InfoPath, but in every other COM application that I have used from .Net (Office objects such as Excel, Word, etc...), that error:
"COM object that has been separated from its underlying RCW cannot be used."
Always means that the Application Object had exited, usually because it threw an unhandled error in its hosted VBA engine.
AFAIK, you cannot stop the Application Object from exiting using .Net code/calls. I'd check your code-behind, if you have any.
Actually looking at your code again:
If Me.fcInfoPath Is Nothing Or wasPrinted Then
...
End If
'This is the line of code that will get the exception, but by the time we get
'here, the COM object has already been released.
Me.fcInfoPath.XmlForm.CurrentView.ForceUpdate()
...
In all likelihood, the Application was already exited even before you got to the Me.fcInforPath Is Nothing .. test. That's an annoying problem when dealing with the .net/COM wrappers, even when the COM object is long gone, the .Net wrapper object persists, so it passes these "Is Nothing" tests, and then only fails when you actually try to use it.
This is an IDE question for Visual Basic 2008 Express Edition. It might be a bug in the IDE, or maybe it's my fault somehow?
My main form is named frmMain and in my application's properties I have set frmMain as my startup object. All of that seems like what a lot of software engineers do.
But while debugging I hit Ctrl + Break, as I have done for years, and I get an behavior in the IDE that I wasn't expecting. Upon doing so, I get the green background text and the green arrow indicating in a tooltip:
This is the next statement to execute when this thread returns from the current function.
Even if I didn't have the designer document open, it automatically opens frmMain.Designer.vb in the editor and hihglights line in green. The line is of course: Partial Class frmMain which is line 2 of the file. (Yes, it's highlighting the second line of the designer-generated code.)
frmMain seems to have fully loaded and it's my startup object. As far as I know, there shouldn't be a "next statement to execute" at all because code should be idle. I don't want to see the Designer.vb document... I want to edit my own code.
What's causing this? Even though my form is behaving just fine, could there somehow be an unfinished aspect of loading the form such that it is "not returning" from a function?
The Visual Basic compiler will add an entry point in your form. The entry point is the standard main function or "shared sub main", which in turn contains the code "application.run(new form)". Since this is compiler generated code there is no source location, so the Visual Basic editor highlights the class definition.
The clue to this is in the call stack. Notice the Main().
Shared Sub Main()
Application.Run(new frmMain)
End Sub
I found the answer on my own:
I checked the "Enable application framework" checkbox in the solution's properties, and all is well!
I believe this issue arose when I was working on experimental code in which I had desired to make Sub Main my startup object. I had cleared the checkbox because doing so is necessary to use Sub Main.
When the experiment didn't pan out I reset the startup object back to frmMain, and my app worked fine. However I had not re-checked the box. I hadn't noticed the change in the IDE behavior for several days (when I needed the more standard behavior) so I had not observed any correlation.
Although checking that box is definitely the solution, it's still not exactly clear to me is what the heck this box actually does, other than cause me to spend a lot of time on StackOverflow.com! ;-)
To others who encounter a similar situation, I'm now quite confident that my settings were not corrupt, and if you're using the Express edition, please don't be mislead by MS documentation which may lead you to believe it's the "Just My Code" option. This option cannot be changed in the Express versions. (But it's not because you can't turn it on -- It's because you can't turn it OFF in Express!)
Thanks to everyone for your efforts.
I'm going to guess that it is trying to show you the equivalent of:
Application.Run(new frmMain)
This is the code that gets generated to startup your form. But in VB.NET this code gets burried. Create a Main() function and change your startup type to that with this line in it and repeat the process. You'll see it highlight Application.Run. That is the method that contains your Windows message pump loop.
I have a problem in my project with the .designer which as everyone know is autogenerated and I ahvent changed at all. One day I was working fine, I did a back up and next day boom! the project suddenly stops working and sends a message that the designer cant procees a code line... and due to this I get more errores (2 in my case), I even had a back up from the day it was working and is useless too, I get the same error, I tryed in my laptop and the same problem comes. How can I delete the "FitTrack"? The incredible part is that while I was trying on the laptop the errors on the desktop were gone in front of my eyes, one and one second later the other one (but still have the warning from the designer and cant see the form), I closed and open it again and again I have the errors...
The error is:
Warning 1 The designer cannot process the code at line 27:
Me.CrystalReportViewer1.ReportSource = Me.CrystalReport11
The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again. C:\Documents and Settings\Alan Cardero\Desktop\Reportes Liquidacion\Reportes Liquidacion\Reportes Liquidacion\Form1.Designer.vb 28 0
I would back up the designer.cs file associated with it (like copy it to the desktop), then edit the designer.cs file and remove the offending lines (keeping track of what they do) and then I'd try to redo those lines via the design mode of that form.
I would take out the static assignment in the designer to the resource CrystalReport11 and then add a load handler to your form and before setting the ReportSource back to CrystalReport11 do a check
If(Not DesignMode) Then Me.CrystalReportViewer1.ReportSource = Me.CrystalReport11
Here is a mockup..
Public Sub New()
InitializeComponent()
AddHandler Me.Load, New EventHandler(AddressOf Form1_Load)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
If (Not DesignMode) Then Me.CrystalReportViewer1.ReportSource = Me.CrystalReport11
End Sub
You should be able to take a backup, clear the lines that are having problems then when you re-open it the designer will fix the code.
The key is that you want to let the designer re-generate, then just validate that all needed lines are there.
That usually works for me, but you just have to be sure to remove all lines that it doesn't like.
I do an easy way; Right Click on the report then choose Run Custom Tool.
Automatically it fixes all problems and working for me, i solve 52 crystal ReportViewer errors.