VB.NET 2008的类型初始值设定项引发了异常 [英] VB.NET 2008 The type initializer for ... threw an exception

查看:193
本文介绍了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!!!

推荐答案

片段"New frmMain"表明这是一种类型.它怎么可能有引用"?您似乎对编程的某些基础一无所知.您显示的代码片段看起来像胡言乱语( http://en.wikipedia.org/wiki/胡言乱语 [ ^ ]).

请执行以下操作:

1)使用Visual Studio从模板创建一个全新的VB.NET程序.使用工具箱将一个或多个控件添加到主窗体.它将为您创建一个完整的应用程序框架.检查其结构并了解其工作原理.您将需要在端口中创建非常相似的内容.

2)熟悉.NET编程和VB.NET的基础知识.学习类型,实例,静态和实例成员,属性,类继承的基础知识和虚拟方法/属性,后期绑定.还要别的吗.是的,但是我已经列出的内容足以开始.确保您完全理解它.您还应该了解,设计器仅可帮助您编写代码(或使某人混淆,这取决于技巧和观点:-));所有编程工件都投射在源代码中,而源代码是在没有设计者任何参与的情况下构建的.

—SA
The fragment "New frmMain" suggests this is a type. How can it possibly have "references"? You seemingly have no idea of some basics of programming. The code fragments you show looks like gibberish (http://en.wikipedia.org/wiki/Gibberish[^]).

Do the following:

1) Create a brand-new VB.NET program with Visual Studio from a template. Add one or too controls to the main form using the Toolbox. It will create you a fully working skeleton of the application. Examine its structure and understand how it works. You will need to create something very similar in your port.

2) Get familiar with basics of .NET programming and VB.NET. Learn types, instances, static and instance members, properties, basics of classes inheritance and virtual methods/properties, late binding. Anything else. Yes, but what I already listed is enough to start. Make sure you thoroughly understand it. You should also understand that the Designer only helps you to write the code (or confuse someone in doing so, it depends on the skills and the point of view :-)); all the artifacts of programming are cast in the source code which is build without any participation of the Designer.

—SA


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

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆