I create a default splash screen using Add New item | Splash Screen and then I select it in the project properties. When I run in it the VB2005 environment, the splash screen shows as expected, but then gives an error message: NullMessageException was unhandled. before running the application. Without the splash screen the application runs fine.
The exception detail follows. Has anybody any idea what I am doing wrong
The funny thing is if I breakpoint the code, depending on where I place the breakpoint in the Splashscreen_load, the exception does not come up. After some experimentation, the problem also may be related to my code. The form load event works fine. The application has a tab page control. Once the form load is finished, the process moves to the TabPage1_Enter event. If I breakpoint at the end sub of the form load of the event, the exception will not subsequently occur. If I step from that breakpoint, the very next event is the TabPage1_Enter. If I breakpoint on the sub declaration of the Enter event, without the earlier breakpoint the exception does occur.
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.Control.WaitForWaitHandle(WaitHandle waitHandle)
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.HideSplashScreen()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.MainFormLoadingDone(Object sender, EventArgs e)
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 OEM_Modbus_Test.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()

Problems with Splash Screen and VB 2005 Express
Craig Butler
Hi,
This is a rare race scenario leading to exception in Windows Forms code. It only happened on certain machines. It has already been reported on http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx FeedbackID=114918. The call stack we've received is the same as yours. A fix has been implemented and will be availabe the next servicing release.
For now, would you please try catching the exception in using UnhandledException (http://msdn2.microsoft.com/en-us/library/3a02k5s0.aspx)
Best regards,
prasannakumar
Sorry I have taken a while to get back- I was away.
It seems to be project specific. I can get it to work with a few simple controls without any hitch occurring.
In the problematic project, there was no code at all in the splash sceen. I tried it with the default splash screen with no changes at all.
-Aubrey
zybernau
I obviously do not have enough expertise to solve this. I tried placing the following code
Public Sub Me_UnhandledException( _
ByVal sender As Object, _
ByVal e As UnhandledExceptionEventArgs _
) Handles Me.UnhandledException
End Sub
' Declaration
Public Event UnhandledException( _
ByVal sender As Object, _
ByVal e As UnhandledExceptionEventArgs _
)
in Form1. It seemed to solve the problem initially, but after 2 or 3 runs the problem returned and since then is always there. I tried to breakpoint in the above, in order to find the error code. I also added
my.application.log.writeexception(e.exception)
to the handler. It never reached any of the breakpoints or the write exception as far as I can tell.
The event description discussed placing code in the ApplicationEvents.vb space so I also tried placing it in the ApplicationEvents.vb which required that I change the line
Public Event UnhandledException(
to
Public Shadows Event UnhandledException(
to get the satisfy the compiler although I have no clue what I am doing. I cannot get it to break anywhere in these modifications. I even tried publishing with the code in form1- still no joy.
Vikram Chudasama
samt
Did you try creating another simple application and adding a splash screen to see if the exception was reproducible in new projects or was specific to this project.
Do you have any user specific code that you have in the splash screen or was it a default generated splash screen in VB 2005 - with just the design time properties changed such as pictures etc. (basically no code changes)
Vladimir Zinchenko
I solved the startup problem- the code in the ApplicationEvents.vb is this
Namespace
My
Partial Friend Class MyApplication
Protected Overrides Function OnInitialize(ByVal commandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String)) As Boolean 'Set the splash screen timeout. 'Me.MinimumSplashScreenDisplayTime = 5000 Return MyBase.OnInitialize(commandLineArgs) End Function Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException End Sub End ClassEnd
NamespaceThe splash problem persists. I have tried to breakpoint on the end sub of the handler- the code never reaches it.
kludge
First thing, ensure a simple application with a splash screen doesn't cause a problem.
Then add just the controls to your form that appear to cause the issue - it' probable that it's not those controls, but something else. Are you updating any data/labels, etc in the splash screen The splashscreen runs on a different thread (and threads always cause problems sooner or later
).
mrmack
I would probably remove the splash screen from the project and reset the splash screen property in My Projects to nothing and then rerun the code to ensure this works correctly.
If it did then I would recreate a new splash screen, not change anything on it and add it to the project and see if the problem comes back.
poodle
Thanks for the suggested approach. The error message gives me no clue as to where to start looking for the problem. Also I am at a loss to explain as to why placing and then stopping on a breakpoint prevents the problem from happening.
I did try adding time delays in several places to see if there was some kind of timing issue, but it didn't resolve anything. I even stretched the splash sceen to 100 seconds without solving the problem. (other than that I did nothing to the splash start up). If I publish the application it does halt with an error.
I am going to abandon the splash screen on this job since the project is too large to start dropping controls in and out. I will try this technique at a much earlier stage in my next project.
Republican Conservative
sandeep_2222
_Tom
Hi,
The correct code to use in ApplicationEvents.vb is
Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException End SubThe IDE can also helps you generate this. With ApplicationEvents.vb opened in the editor, under the tab there are 2 combo boxes
Best regards,
Brian Combs MSFT
Hi,
This will let the application ignore the exception and continue.
Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledExceptione.ExitApplication = False
End Sub
However, after the application is closed down, Windows will try to report this unhandled exception. I could not find a way to get this ignored. I could not find a better work-around either since this exception is not happening on any of my machines. Did changing the splash time out help at all
A work-around was suggested on Connect web site as well https://connect.microsoft.com/VisualStudio/feedback/Workaround.aspx FeedbackID=114918.
Saber01
Moving this thread to the Visual Basic Express Edition forum.
-Tom Meschter
Software Dev, Visual C# IDE