We have just converted a large VB6 desktop app to VB.NET 2008. First via the VB 2005 (open project), then days of fixing errors, etc. Then opened the VB 2005 in VB 2008 so now it is a 2008 solution.

The more we try to test the worse it gets. It did start and crash with typical errors but now it does not even get off the ground.

Message InvalidOperationException was unhandled.

... The type initializer for .... threw an error.

Have seen many searches via google but no solution that I can understand.

App framework is enabled, it is using .net 3.5.

The more we try to fix the earlier it crashes. The 1st form load does not even start (break point not stopped on but it did before and failed on AppFrameWorkOn = True where AppFramWorkOn is just a boolean in another module. Except same code works in other programs.

We have written several dozen other VB.Net 2005 programs but this one just doesn't make sense.

There is also no Configuration Manager in the Build menu. Can't understand that either.

There are no errors when we do a build.
There are about 30 forms with code behind and about 40 other modules.

Help!!!! Bring back VB6.

It seems to be related to forms such as
Public FormMain as frmMain = frmMain

This technique worked in many other programs but not this one. Not sure why.

The 1st form load does not even start..

Means there is either something wrong in the application.vb (startup event)
Or, which i could bet on, there is a problem in the initializing of the form.

So, have you tried to view the startup form in the designer? This should already throw some errors. If not, then open the <form>.designer.vb and set a breakpoint at "InitializeComponent" and step through it.

Hi QuickBooksdev

I have gone through same case as yours when trying to convert from VB6 to VB.Net

I think your references for each forms and the autogenerated code for Tools and forms might have some issues.

If u still could see your design view of forms then its ok... If not you might used special tool controls which needs some powerpacks to be installed for viewing and running using .Net framework.. Otherwise check the list of forms which is used as child window for the main form and check it references is correct or not....Also check whether the Main form is refered as Me in designer.vbx ...

Some normal text like To,With etc in VB6 will be recognized as keywords in .Net so check if you have captions with the keywords which creates bug in designer.vbx .....

In simple, check the components in your form which initialize during runtime..


Rgrds

Sam

It is crashing on
Public FormStores As frmMain = frmMain
which is in a module. frmMain is my startup form.

This is the same technique used in many other programs 2005 and 2008.

I can put a breakpoint on it and it will no do the next instruction but continues with some of the control text changed events, etc. and then to frmMain.load.

The inner exception is 'The form referred to itself during construction of a default instance, which led to an infinite recusion. ...'

I don't understand why it works fine in many other programs including VB6 converted programs but not this one.


Code
... frmMain.load
.

AppFrameWorkOn2 = True ' Crashes here with error because
Public FormStores As frmMain = frmMain fails which is in a base module before the def of AppFramWorkOn
Module aaaBase
.
.
.
Public FormStores As frmMain = frmMain
Public AppFrameWorkOn As Boolean, AppFrameWorkOn2 As Boolean = False

I have tried moving it to the top of the module and to the bottom before any subs or functions and it always fails (no error but the instruction below it does not execute).

Running on W7/64 but in x86 mode.

try:
Public FormStores As Form = new frmMain

That may give me different results since I wish FormStores to point to frmMain and not be a different instance. It also does not explain why the other programs work but this one does not.

I will play with it.

Tried it and although it does not have the same problems as previously it definetely gives me different results and does create duplicates of the form so settings which are changed are not picked up in the new instance. So not really usuable.

Why does this problem fail and the half dozen or more using the same technique work fine?

Can anyone help me with this?

Just don't understand how in VB.NET the same technique used in 6-7 programs fails in this one?

VB.NET does not istantiates the forms by default as does VB6.

So probably when you Public FormStores As frmMain = frmMain you are expecting that frmMain already exist, but does not.

I would suggest some code like this to instantiate the child form:

Public FormStores As frmMain

Public Sub New (ref formMain)

    MyBase.New()
    InitializeComponent()
    FormStores = formMain

End Sub

Then on the calling form or module

Dim ChildForm as cForm = new cForm(frmMain)

Hope this helps

Don't know. Why is it working in other programs? I would think that your ChildForm would be a new form and that controls on frmMain could not be referenced via ChildForm.

i.e.
if intitial setting frmMain.checkBox1.checked = false
then
someone checks checkBox1 on frmMain

the ChildForm.checkbox1.checked would be false.

Please advise.

Gets more confusing.

I am looking 2 VB.Net2008 programs. Both are AppFrameWork enabled with frmMain as the startup.
Both have
Public FormMain as frmMain = frmMain in a module.

When the working program runs the CheckedChanged event runs and it goes to the module with FormMain is. So I guess frmMain does exists and then to frmMain's MyBase.Load

When the failing program runs it does the module with FormMain first then the control changed events. This is probably BEFORE frmMain is created. So why the difference.

Yes. That is.

In .Net any form exist until is instantiated.
Th frmMain is instantiated by the CLR bootstrap only if it is the starting form of the project.

If your project starts from a Sub Main in a module, then you need to declare and instantiate the frmMain as any other.

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.