I am currently trying to create a simple client (Initiator) using QuickFix with a graphical user interface. I'm using Visual Studio 2012 and programming in VB.Net.
Here is my problem : When I launch my app, I have this error : "An unhandled exception of type 'System.InvalidOperationException' occurred in WindowsApplication1.exe
Additional information: An error occurred creating the form. See Exception.InnerException for details. The error is: The form referred to itself during construction from a default instance, which led to infinite recursion. Within the Form's constructor refer to the form using 'Me.'"
I have two files in my project which are Client GUI.vb (http://pastebin.com/virgVNyS) and MyQuickFixApp.vb (http://pastebin.com/tQ1GXNSx). The second one contains the class that integrates the IApplication, with all the subs.
The error happens when it executes this line : "Dim initiator As New SocketInitiator(myApp, storeFactory, settings, logFactory)" from Client GUI.vb but the software highlights a line from the file Application.Designer.vb which is :
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.WindowsApplication1.ClientGUI
End Sub
Can you help me and tell me what is wrong ?
Thank you very much !
When dealing with WinForms, the best proceeding to avoid problems is initialise everything (except simple variable assignation, for example: Dim filename As String = "initiator.cfg"
is fine) after the GUI has been constructed/loaded (on the _Load
method). The reason why you are getting this error is because of referring to the main Form (Me.MainForm =
) before it has been actually created.
Move Dim initiator As New SocketInitiator(myApp, storeFactory, settings, logFactory)
to ClientGUI_Load
(the Load Event
method of your main form) and the error will disappear.
NOTE: if you want to access initiator
from "anywhere", you should keep the global declaration but move the assignation to the Load event, that is:
Dim initiator As SocketInitiator 'at the Class level, outside any sub/function (as previously)
And
initiator = New SocketInitiator(myApp, storeFactory, settings, logFactory) 'Inside the ClientGUI_Load method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With