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
anwarmirAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Sounds like a bug to me.

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

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

Bob

 
0
anwarmirAuthor Commented:
Sorry But i a have just started VB.net...can someone explain a bit further.
Any tips on how i can resolve the problem.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Bob LearnedCommented:
What are you trying to do?

Bob
0
anwarmirAuthor Commented:
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
0
Bob LearnedCommented:
Why are you trying to avoid the exception?  It could be possible to "hide" an exception that you need to see that way.

Bob
0
anwarmirAuthor Commented:
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
0
Bob LearnedCommented:
You could try this:

   Public Overloads Overrides Function Equals(ByVal obj As Object) As Boolean
        If obj Is Nothing OrElse 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

The OrElse operator is different than the Or operator, in that it performs shortcut boolean expression evaluation.  If the 'obj Is Nothing' is False, then the expression will not be evaluated any further, and you won't get that exception.

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anwarmirAuthor Commented:
Thanks....This seems to work.
Appreciate your help on this one.
Cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.