Link to home
Create AccountLog in
Avatar of anwarmir
anwarmir

asked on

An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll

Hi can u help me please i get the following error msg:

 An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll

when the follwoing code is executed : Catch When Not System.Diagnostics.Debugger.IsAttached

Can anybody help ????


#If DEBUG Then
            Catch When Not System.Diagnostics.Debugger.IsAttached
#Else
            catch
#End If

                'Just re-throw here, exception handled by BaseApplication
                Throw

            Finally

                'Log end of application
                BaseApplication.goError.Log("SESSION FINISHED", [Error].SeverityLevel.Information)
                'Stop base application
                BaseApplication.Stop()

            End Try

        Else
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Sounds like a bug to me.

Bob
This is the resulting call from the framework (pretty simple):

<MethodImpl(MethodImplOptions.InternalCall)> _
Private Shared Function IsDebuggerAttached() As Boolean
End Function

Bob

 
Avatar of anwarmir
anwarmir

ASKER

Sorry But i a have just started VB.net...can someone explain a bit further.
Any tips on how i can resolve the problem.
What are you trying to do?

Bob
I have started supporting a new system the code has already benn written.

It appears that the exception is being thrown by the following function, on the first line of the code:

obj Is Nothing Or Not Me.GetType Is obj.GetType

    Public Overloads Overrides Function Equals(ByVal obj As Object) As Boolean
        If obj Is Nothing Or Not Me.GetType Is obj.GetType Then
            Return False
        End If
        Dim order As ViewedOrder = CType(obj, ViewedOrder)
        Return order.Id = Me.Id And order.Customer = Me.Customer
    End Function

Is there any way i can put some saftey checks in the Function so that the exception is not thrown

Thanks
Why are you trying to avoid the exception?  It could be possible to "hide" an exception that you need to see that way.

Bob
The thing is the exception in this function appears to crash the whole application. Is there any way round this?
I know i am not giving you much to go on...but ia m still in the early days of struggling to understand the application.
Thanks
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thanks....This seems to work.
Appreciate your help on this one.
Cheers