Code generation for property <propertyname> failed: Property accessor on object threw ... Object reference not set ...

Daniel Wilson
Daniel Wilson used Ask the Experts™
on
I have added a property to a user control.  At runtime, it functions flawlessly.  At design time, however, I am repeatedly interrupted by the error:
Code generation for property 'HideAddins' failed. Errors was: 'property accessor 'Hideaddins' on object <mycontrol> threw the following exception: 'Object reference on set to an instance of an object.''

I have code in which should absolutely prevent an 'Object reference not set' condition.  I also have code which should trap it, should it somehow occur.  I also have attributes in place to try to get the property left alone at design time.  All to no avail.

What am I doing wrong?

Thanks!
<Browsable(False)> _
    <DefaultValue(False)> _
    Public Property HideAddins() As Boolean
        Get
            Try
                If Not tcNotes Is Nothing AndAlso Not tcNotes.TabPages Is Nothing Then
                    Return Not tcNotes.TabPages.ContainsKey("tpAddIns")
                Else
                    Return False
                End If
            Catch
                Return False
            End Try
        End Get
        Set(ByVal value As Boolean)
            Try
                If Not tcNotes Is Nothing AndAlso Not tcNotes.TabPages Is Nothing Then
                    If value Then
                        'tcNotes.TabPages("tpAddIns").Hide()   '.IsAccessible = Not value
                        If tcNotes.TabPages.ContainsKey("tpAddIns") Then tcNotes.TabPages.RemoveByKey("tpAddIns")
                    Else
                        'tcNotes.TabPages("tpAddIns").Show()
                        If Not tcNotes.TabPages.ContainsKey("tpAddIns") Then tcNotes.TabPages.Add(tpAddIns)
                    End If
                End If
            Catch
            End Try
        End Set
    End Property

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2015
Commented:
This may be a moot point, but I seem to recall "Not [something] Is Nothing" not working for me and that I had to use "[something] IsNot Nothing" instead.

Author

Commented:
Ok, thanks, changed that ... and the test app seemed to do better ... but my real app is having as much trouble as ever.

Working to see if something may be cached ...

Author

Commented:
Yes, after thoroughly getting rid of cached junk & restarting Visual Studio, it worked!

Author

Commented:
Thanks!  I never would have suspected that one as being my problem!
Most Valuable Expert 2011
Top Expert 2015

Commented:
NP. Glad to help  :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial