hey guys,
I'm very new on this forum and very new in .net as well. I'm trying to make a small software for my school. I'm using basic windows froms and stuff. I've multiply forms which are connected. Everything was working fine but i believe when i tried to fill the datagrid then it started to give me following error in the main form:
System.TypeInitializationException was unhandled
Message="The type initializer for 'WindowsApplication1.mdlMain' threw an exception."
Source="Test"
TypeName="WindowsApplication1.mdlMain"
StackTrace:
at WindowsApplication1.frmMain.frmMain_Load(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Test\Test\frmMain.vb:line 25
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
I really don't know how to find the solution or debug it properly to solve the problem. Please help thanks in advance!

Type Initializer therw an exception
Lord Finn
Allright
do you have any idea when it would come out Thanks for the replys though! 
ar3
Not really, because i'm getting the problems in the main form which runs at the start. so i don't knwo what to do with it.
It starts giving me the error on following part first:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load GierrNumber = GobjDAC.OpenConnection(GstrErrorMessage) End SubIf i comment that part then it starts giving me the same error in other parts of the codes on the same form for example following :
Private Sub bRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bRegister.ClickfRegister =
New frmRegister()fRegister.ShowDialog()
Me.Hide() End SubThere's nothing much i can do about, can i
leemcd
at WindowsApplication1.frmMain.frmMain_Load(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Test\Test\frmMain.vb:line 25
What is on line 25 of this form I've found that the forms designer does all sorts of strange, crappy stuff when initialising your forms to show them in the forms view, and is often less than helpful in trying to tell you what the problem was. I had one app where the form design view crashed the IDE, it turned out that a control I wrote which had a Bitmap property was being set with a Bitmap of pixel format Undetermined, which I didn't know existed, and my code just checked for null, being the only sensible value apart from what I was passing in, myself.
So, check that line, it's probably setting something on a control, and the thing it's setting is not properly initialised when this method is called by the form designer.
nater1111
Thanks for the reply! I guess you're right it could be the designer problem. I tried to comment that part but then it starts to giving same errors for other part of the code. The most strange things is that everything was working fine but when i added a new form and tried to implement that one then it started to giving that error and if exculde that form from my project then everything seems working fine, no errors and stuff!
I really don't know what to do
Emil Christopher Melar
This error means it's when it's initializing static things on the class.
For example, initializing private members of the class, or within a static constructor.
Although MS don't recommend it for performance reasons, I find it good to put the initialization of private static members in a static constructor rather than inline.
That way you can put a breakpoint in the static constructor and step through until you see what blows.
Matt
(These a C# terms, not sure how VB.Net terms may differ)
PFI
No, it sounds like you're stuck until the Forms designer is repaired.
Nevan
So it blows up when calling the method, but not when you run it. Sounds like typical VS2005 designer *** to me. Unless someone else has any suggestions, you could be like me, unable to use the designer until the patch comes out. However, I would try commenting out individual lines within the method and see if the designer works, and if it does, look into the line that fixes it. Remember, the designer can pass stupid values to your properties sometimes.
wacher
This is the code on line 25:
Private
Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loadcmckeegan