Link to home
Start Free TrialLog in
Avatar of Daniel Wilson
Daniel WilsonFlag for United States of America

asked on

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

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

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daniel Wilson

ASKER

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 ...
Yes, after thoroughly getting rid of cached junk & restarting Visual Studio, it worked!
Thanks!  I never would have suspected that one as being my problem!
NP. Glad to help  :)