Jump to content
Xtreme .Net Talk

VB.NET 2008 The type initializer for ... threw an exception


Recommended Posts

Posted

We have not added any code to instantiate it.

 

 

 

In a working program that uses the same technique.

 

I hit F8 to step thru.

 

 

1. It goes into some CheckChanged events on frmMain so I assume the form is instantiated.

 

 

2. It then goes into the module with Public FormMain as frmMain = frmMain where it completes the definitions ok (does the last).

 

3. Then it goes to frmMain's MyBase.load

4. Program runs fine

 

 

In the failing program I hit F8

 

1. It immediately goes to the module with Public FormMain as frmMain = frmMain

(frmMain probably NOT instantiated)

 

2. The module definitions do not complete (last statement executed is the FormMain).

 

3. It goes to other modules for defintitions

 

4. It now goes to the ..Changed events on frmMain (on working programs this was first).

 

5. It then goes to the frmMain MyBase.load

 

 

 

So the failing program is taking a different startup path and I do not know why.

 

What would cause the modules to be executed first before frmMain is instantiated?????

  • Leaders
Posted

One thing worth noting is that when you have declarations with initializers (such as Public FormMain as frmMain = frmMain), even though you don't write the code in the Sub New (i.e. the class constructor or type initializer), when the program is compiled, that is where it ends up, so an error on a field initializer can result in a type initializer exception.

 

What you really need to do is catch the exception right off the bat. For some reason, the originating exception is not being caught, and you're getting the resulting type initializer exception. If nothing else works out, you should be able to see the original exception in the InnerException property of the type initiailizer exception, which should include a stack trace.

 

It would help to set VS to break when any exception is thrown. If you go to "Exceptions" under the "Debug" menu, in the dialog that appears there are two columns of checkboxes. By default only "User-unhandled" is checked. Try checking the "Thrown" box as well. (You can probably leave "Managed Debugging Assistants" alone). Hopefully that will get VS to show you the root cause of the problem.

[sIGPIC]e[/sIGPIC]
Posted

We will try to debug change to see where it gets the error but I have a workaround now.

 

We took out the = frmMain from the module and moved it to frmMain itself. That seemed to solve that part. We are now debugging other VB6 conversion issues.

 

Thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...