Solved

VB.NET IDE Not throwing errors?

Posted on 2011-03-12
22
481 Views
Last Modified: 2012-05-11
I have the following in a form:

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Dim Engine As TVEngine, Tex As TVTextureFactory, lngID As Long
      Engine.Init3DNoRender(Me.Handle)
      lngID = Tex.CreateTexture(48, 48)
   End Sub

Open in new window


This SHOULD throw an error since the Engine and Tex objects haven't been "instantiated."  (Am I using that term correctly?)  Instead, the form opens as if there's no problems.

I assume I've changed some obscure setting somewhere accidentally, though why this setting would exist is beyond me.  

Help!

-Javin
0
Comment
Question by:Javin007
  • 12
  • 7
  • 3
22 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 35116041
Engine and Tex in your example are variables which you are declaring. VB.NET IDE i correct NOT to throw an error / warning.
0
 
LVL 4

Author Comment

by:Javin007
ID: 35116059
Sorry, but you're wrong.  Engine and Tex are objects that are declared but are not being instantiated.  VB.NET SHOULD (and used to) throw exceptions when they are called.
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 35116161
Here goes a leson in the basics

1. Dim Engine As TVEngine

In the above, Engine is a variable TVEngine is the object

2. Dim Tex As TVTextureFactory

In this case Tex is the variable and TVTextureFactory is the object.

If your question was about TVTextureFactory and TVEngine not being instantiated, and therefore should throw errors, then fair comment, VB should and will.

Check your references, the objects may be declared in one of your custom references, and you have forgoten! (easy to do as is confusing variables with objects)
0
 
LVL 4

Author Comment

by:Javin007
ID: 35116247
*sigh*  I don't need a "leson in the basics (sic)" as I've been programming for 26 years.  

Dim Engine as TVEngine

In this case, TVEngine is the class, and Engine is an "instance" of that class, also called an "object."  I'm not going to argue semantics with you, as there's no point.  Sure, you could argue that Engine is just a variable holding a pointer to the memory location of the instance of the object, but this is not the point.

Engine.Init3DNoRender(Me.Handle)

Here, a function of the Engine OBJECT is being called, despite the fact that the object was not instantiated.  This should throw an exception and used to at the point that this is called.  However, the form opens, no errors are thrown, and the code is entirely skipped.  Putting a break in the Form_Load event shows that the code never executes.

This is what I'm trying to figure out.  There SHOULD be an error thrown, and the code SHOULD attempt to execute, but it does not.  The form simply opens.

-Javin
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 35116271
Hi Javin007;

Lets make sure that your Exceptions and Debug settings are not causing this. On the main menu click on Debug -> Exceptions.... When the Exceptions window opens click on "Reset All", this will reset all the exception setting to the default setting as when first installed VS. Now try executing the code.

Fernando
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 35116286
I give up!
0
 
LVL 4

Author Comment

by:Javin007
ID: 35116407
Thanks, Fernando.  

I tried the reset, still no dice.  Form's still opening with no errors.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 35116674
That leads me to believe that there is an instance of it somewhere or TVEngine has a static version.
0
 
LVL 4

Author Comment

by:Javin007
ID: 35116727
Newp.  TVEngine definitely doesn't, and as this is literally the ONLY code in the app, it's not instantiated anywhere else.  This code specifically used to throw errors all the time.  The code isn't even EXECUTING.  Debug.Print shows that it never executes the Form_Load event.

Is it possible that the "Handles MyBase.Load" could be wrong?
0
 
LVL 4

Author Comment

by:Javin007
ID: 35116745
So I've reduced the code down to this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   Debug.Print("Working!")
End Sub

Open in new window


This outputs "Working" to the immediate window.

Then I change the code (bear in mind, this is 100% of the code in the entire project) to the following:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   Dim Engine As TVEngine
   Debug.Print("Working!")
End Sub

Open in new window


Now the word "working" does not appear in the immediate window, putting a break point on either line does not trigger anything, no errors are thrown, but the form still opens.

Definitely something stupid happening with the VB IDE.  I've even tried to download/reinstall it, but it seems to keep the old settings with a reinstall.  I assume there's some bizarre setting somewhere that says, "Don't show me anything at all, I'll just psychically determine when and where errors occur."
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 35116784
What is TVEngine? Is there a web site that you can post so that I may do some research.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 4

Author Comment

by:Javin007
ID: 35116855
TVEngine is a DirectX wrapper that I've used for years (www.TrueVision3D.com).  I can assure you the problem isn't with the wrapper.  This USED to throw the errors correctly, and then one day it just simply stopped throwing these exceptions.  My suspicion is that there's a bad reference to the TV3D dll, but this should throw an error instead of simply opening the form and not executing the code in the event.  It's not even limited to just this one situation.  My VB IDE is doing all kinds of weirdness.  In other obvious errors (syntax problems and whatnot) it takes me to an odd "can not find source" page and stops the execution without highlighting where the problem is.
0
 
LVL 4

Author Comment

by:Javin007
ID: 35116856
I'm currently in the process of uninstalling and removing all traces of VB.NET Express from my system, and will attempt a full reinstall once this is done.
0
 
LVL 4

Author Comment

by:Javin007
ID: 35117130
ARRRRGH!  Full uninstall and reinstall of VB.NET Express and no change.  This is driving me insane.
0
 
LVL 4

Author Comment

by:Javin007
ID: 35117143
I've even created a completely new project, thinking something may be corrupt in the project itself.  This is 100% of the code in the project:

Imports MTV3D65

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Engine As TVEngine
        Debug.Print("Working")
    End Sub
End Class

Open in new window



Executing this does NOT output "Working" to the Immediate Window.  However if I comment out the Dim Engine As TVEngine line, it does.

Please help!
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 35117253
Hi Javin007;

I think I have an answer for you so give me some time to write it up and post it.

Fernando
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 35117426
Hi Javin007;

This is what I found. Lets start with this code line numbers just for reference.

01 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
02    Dim Engine As TVEngine, Tex As TVTextureFactory, lngID As Long                              
03    Engine.Init3DNoRender(Me.Handle)                                                                   
04    lngID = Tex.CreateTexture(48, 48)
05    Debug.Print("Working!")
06 End Sub

Open in new window


Line 03 above will cause a unhandled exception of type null reference. When that happens the system will look for an exception handler to match the type of exception and when it does not find one it displays the form but all statements after the exception are not executed. I believe this is a function of working in the development environment. To prove this if you navigate to the bin directory of the project with Windows Explorer and double click on the executable, ProjectName.exe and NOT ProjectName.vshost.exe, You will receive the Microsoft .Net Framework dialog box and the program will be terminated. Now to see a similar thing in the IDE you can do the following. On the main menu click on Debug -> Exceptions... When the dialog box opens click on Common Language RunTime Exceptions node to expand it. Look down the list to find the entry for System.NullReferenceException and place a check mark in the check box for Thrown. The click OK and compile and run in the IDE. The execution will stop on line 03 of the code above. Now if you place the Debug.Print message before the exception it should print to the IDE's Output window as it does on my machine. Also don't forget to reset the exception I had you place in the configuration above.

This version of the code will catch the exception print a message and then dump you to the form.

Dim Engine As TVEngine
Dim Tex As TVTextureFactory
Dim lngID As Long

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try
        Engine.Init3DNoRender(CInt(Me.Handle))
        lngID = Tex.CreateTexture(48, 48)
    Catch ex As Exception
        Debug.Print(ex.Message)
        ' When the Return statement is executed the form will be displayed
        ' as was with your initial attempt but the below Debug.Print will not show.
        Return
    End Try
    Debug.Print("Working")
End Sub

Open in new window


Fernando
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 35117444
Hi Javin007;

Sorry in the above post I had the following statement :

On the main menu click on Debug -> Exceptions... When the dialog box opens click on Common Language RunTime Exceptions node to expand it.

Should read as :

On the main menu click on Debug -> Exceptions... When the dialog box opens click on Common Language RunTime Exceptions node to expand it then expand the System node.

Fernando
0
 
LVL 4

Author Comment

by:Javin007
ID: 35117499
Unfortunately, I've already gone down that road.  I've set *EVERYTHING* to "throw" in the "exceptions" section.  Still nothing.  The code has been reduced to this:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Debug.Print("Eh?")
        Try
            Dim Engine As TVEngine, Tex As TVTextureFactory
        Catch ex As Exception
            Debug.Print("Failed.")
        End Try
        Debug.Print("Finally!")
    End Sub

Open in new window


There's not even an attempt to call a method here, this is ONLY trying to DECLARE the variable.  Still, when I execute this code, absolutely NOTHING prints in the immediate window.  If I comment out the "Dim" line I will get "Eh?" and "Finally!" printed.  Just by declaring the object the IDE is pretending not to see the sub at all.
0
 
LVL 4

Assisted Solution

by:Javin007
Javin007 earned 0 total points
ID: 35117542
I've found the solution (though I'll give you the points for the effort, Fernando.)

After much pain, I found that by adding a new app.config file to the application, then adding this:

  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>

To the file, it now works as expected.  It was in fact related to the DLL as you had suspected, but was rather tied to the version of the framework apparently.  

What a pain.  Two days of programming time lost on this.  :/

-Javin
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 35117569
Well glad to here you found the issue. Have a great day.
0
 
LVL 4

Author Closing Comment

by:Javin007
ID: 35154524
Note that this particular solution was due to a need for an app.config entry.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now