Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-03-24
9
Medium Priority
?
1,785 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:anwarmir
  • 5
  • 4
9 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16286136
Sounds like a bug to me.

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16286153
This is the resulting call from the framework (pretty simple):

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

Bob

 
0
 

Author Comment

by:anwarmir
ID: 16299283
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 16300531
What are you trying to do?

Bob
0
 

Author Comment

by:anwarmir
ID: 16310280
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16310303
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
 

Author Comment

by:anwarmir
ID: 16310355
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 16310379
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
 

Author Comment

by:anwarmir
ID: 16310470
Thanks....This seems to work.
Appreciate your help on this one.
Cheers
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question