• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

VB.NET IDE Not throwing errors?

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
Javin007
Asked:
Javin007
  • 12
  • 7
  • 3
2 Solutions
 
nepaluzCommented:
Engine and Tex in your example are variables which you are declaring. VB.NET IDE i correct NOT to throw an error / warning.
0
 
Javin007Author Commented:
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
 
nepaluzCommented:
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Javin007Author Commented:
*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
 
Fernando SotoRetiredCommented:
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
 
nepaluzCommented:
I give up!
0
 
Javin007Author Commented:
Thanks, Fernando.  

I tried the reset, still no dice.  Form's still opening with no errors.
0
 
Fernando SotoRetiredCommented:
That leads me to believe that there is an instance of it somewhere or TVEngine has a static version.
0
 
Javin007Author Commented:
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
 
Javin007Author Commented:
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
 
Fernando SotoRetiredCommented:
What is TVEngine? Is there a web site that you can post so that I may do some research.
0
 
Javin007Author Commented:
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
 
Javin007Author Commented:
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
 
Javin007Author Commented:
ARRRRGH!  Full uninstall and reinstall of VB.NET Express and no change.  This is driving me insane.
0
 
Javin007Author Commented:
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
 
Fernando SotoRetiredCommented:
Hi Javin007;

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

Fernando
0
 
Fernando SotoRetiredCommented:
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
 
Fernando SotoRetiredCommented:
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
 
Javin007Author Commented:
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
 
Javin007Author Commented:
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
 
Fernando SotoRetiredCommented:
Well glad to here you found the issue. Have a great day.
0
 
Javin007Author Commented:
Note that this particular solution was due to a need for an app.config entry.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 12
  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now