本文介绍了VB.NET 2008的类型初始值设定项引发了异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们刚刚在Win 7/64上将一个大型VB6程序(30个带有代码后面的屏幕和40个模块转换为VB.Net,首先是2005年,然后是2008 Net 3.5),但是以x86模式运行.
它使用与我们其他.Net应用程序相同的技术,并具有多个指向相同真实形式的形式变量,即

We have just converted a large VB6 program (30 screens with code behind and 40 modules to VB.Net, First 2005 and then 2008 Net 3.5) on Win 7/64 but running in x86 mode.

It uses the same techniques as our other .Net apps with multple form variables pointing to the same real form i.e.

Public FormMain as frmMain = frmMain
Public FormStores as frmMain = frmMain


这在一个模块中. frmMain 是启动表单.已启用应用程序框架.

这已经在其他程序中运行了好几年了.

但是,使用此程序会失败.
第一个= frmMain得到一个直到稍后才出现的异常
(此后的指令不执行.)

稍后我们得到
...的类型初始值设定项引发了异常
内部异常是
''该格式在构造默认实例时引用了自身,这导致了无限的回避. ...''


AppFrameWorkOn2 = True


之后Public FormMain as frmMain = frmMain

为什么这在此程序中不起作用,但在其他程序中起作用?

尝试过
Public FormMain As New frmMain
这不会导致错误,但是结果会有所不同. FormMain 不再是对frmMain 的引用,而是一种全新的形式,并且随着用户对其进行更改,控件设置也会有所不同.

如何使它正常工作?


This is in a module. frmMain is the startup form. Application Framework is enabled.

This has been working in other programs just fine for years.

However with this program it fails.
The first = frmMain gets an exception that doesn''t show up until later
(the instructions after this one do not execute).

Later we get
The type initializer for ... threw an exception
The inner exception is
''The form referred to itself during construction of a default instance, which led to an infinite recusion. ...''

on
AppFrameWorkOn2 = True

which is AFTER the
Public FormMain as frmMain = frmMain

Why is this not working in ths program but does in others?

Have tried
Public FormMain As New frmMain
which does not cause the error but this has different results. FormMain is no longer a reference to frmMain but a totally new form and the controls settings will be different as the user changes them.

How do I get this to work??

Please help!!!

推荐答案


这篇关于VB.NET 2008的类型初始值设定项引发了异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-15 22:10