Home All Groups Group Topic Archive Search About

Delegate property and component serialization

Author
5 Oct 2005 3:08 AM
Arthur Dent
Hello all...

I have a component which i wrote, which is used for automatically emailing
errors, so that when an app (usually a website) goes into production, i
automatically get emailed about any exceptions which occur on the site. A
friend wanted to use the same thing but have the ability to override the
OnError action, because their mail handler had to be handled in an unusual
manner.

To accomodate his need, i added a delegate definition to the component. Now
it allows the user to either accept the intrinsic behaviour or replace it
with their own... for an odd email handler, or logging or simply
messageboxing the user.

The only problem is now i cannot drag the component onto a form designer
anymore, because it says the Handler property is not serializable.
Is there any way that i can get around that? Isnt a delegate basically a
function pointer? which is basically an Int? which should be serializable?

My code (partial/relevant) is as follows:
===== BEGIN CODE ==============================================
Public Class ErrorHandler
    Inherits System.ComponentModel.Component

    Delegate Sub ExceptionHandler(ByVal ex As Exception, ByVal OneTimeExtra
As String)
    Private pHandler As ExceptionHandler = AddressOf PrivateHandler

    Public Property Handler() As ExceptionHandler
        Get
            Return pHandler
        End Get
        Set(ByVal Value As ExceptionHandler)
            If Value Is Nothing Then _
                pHandler = AddressOf PrivateHandler _
            Else _
                pHandler = Value
        End Set
    End Property

    Private Sub PrivateHandler(ByVal ex As Exception, ByVal OneTimeExtra As
String)
        ..... <intrinsic handling>
    End Sub
End Class
===== END CODE ================================================

Thanks in advance,
- Arthur Dent.

Author
5 Oct 2005 8:14 AM
cody
You should use events instead of delegates directly for this so the problem
should go away.
If not, you can mark the delegate property with the
<DesignerSerialisationVisibility(DesignerSerialisationVisibility.Hidden)>
attribute.


Show quote
"Arthur Dent" <hitchhikersguideto-n***@yahoo.com> schrieb im Newsbeitrag
news:e3fOSoVyFHA.3812@TK2MSFTNGP09.phx.gbl...
> Hello all...
>
> I have a component which i wrote, which is used for automatically emailing
> errors, so that when an app (usually a website) goes into production, i
> automatically get emailed about any exceptions which occur on the site. A
> friend wanted to use the same thing but have the ability to override the
> OnError action, because their mail handler had to be handled in an unusual
> manner.
>
> To accomodate his need, i added a delegate definition to the component.
> Now it allows the user to either accept the intrinsic behaviour or replace
> it with their own... for an odd email handler, or logging or simply
> messageboxing the user.
>
> The only problem is now i cannot drag the component onto a form designer
> anymore, because it says the Handler property is not serializable.
> Is there any way that i can get around that? Isnt a delegate basically a
> function pointer? which is basically an Int? which should be serializable?
>
> My code (partial/relevant) is as follows:
> ===== BEGIN CODE ==============================================
> Public Class ErrorHandler
>    Inherits System.ComponentModel.Component
>
>    Delegate Sub ExceptionHandler(ByVal ex As Exception, ByVal OneTimeExtra
> As String)
>    Private pHandler As ExceptionHandler = AddressOf PrivateHandler
>
>    Public Property Handler() As ExceptionHandler
>        Get
>            Return pHandler
>        End Get
>        Set(ByVal Value As ExceptionHandler)
>            If Value Is Nothing Then _
>                pHandler = AddressOf PrivateHandler _
>            Else _
>                pHandler = Value
>        End Set
>    End Property
>
>    Private Sub PrivateHandler(ByVal ex As Exception, ByVal OneTimeExtra As
> String)
>        ..... <intrinsic handling>
>    End Sub
> End Class
> ===== END CODE ================================================
>
> Thanks in advance,
> - Arthur Dent.
>
Author
5 Oct 2005 12:45 PM
Arthur Dent
The only thing which i would see as a problem with using events is that
i want the custom handler to completely supplant the built-in handler
(if a custom one is specified). If i used events, and the consumer handled
the event, then it would happen *in addition to* the built in handler as
opposed
to *instead of*, no?

Thanks for the response. The DesignerSerialisationVisibility, will that have
any effects
on the component as far as it "forgetting" who the current handler-routine
is?

Thanks again.


Show quote
"cody" <deutron***@gmx.de> wrote in message
news:uB8BHTYyFHA.3864@TK2MSFTNGP12.phx.gbl...
> You should use events instead of delegates directly for this so the
> problem should go away.
> If not, you can mark the delegate property with the
> <DesignerSerialisationVisibility(DesignerSerialisationVisibility.Hidden)>
> attribute.
>
>
> "Arthur Dent" <hitchhikersguideto-n***@yahoo.com> schrieb im Newsbeitrag
> news:e3fOSoVyFHA.3812@TK2MSFTNGP09.phx.gbl...
>> Hello all...
>>
>> I have a component which i wrote, which is used for automatically
>> emailing errors, so that when an app (usually a website) goes into
>> production, i automatically get emailed about any exceptions which occur
>> on the site. A friend wanted to use the same thing but have the ability
>> to override the OnError action, because their mail handler had to be
>> handled in an unusual manner.
>>
>> To accomodate his need, i added a delegate definition to the component.
>> Now it allows the user to either accept the intrinsic behaviour or
>> replace it with their own... for an odd email handler, or logging or
>> simply messageboxing the user.
>>
>> The only problem is now i cannot drag the component onto a form designer
>> anymore, because it says the Handler property is not serializable.
>> Is there any way that i can get around that? Isnt a delegate basically a
>> function pointer? which is basically an Int? which should be
>> serializable?
>>
>> My code (partial/relevant) is as follows:
>> ===== BEGIN CODE ==============================================
>> Public Class ErrorHandler
>>    Inherits System.ComponentModel.Component
>>
>>    Delegate Sub ExceptionHandler(ByVal ex As Exception, ByVal
>> OneTimeExtra As String)
>>    Private pHandler As ExceptionHandler = AddressOf PrivateHandler
>>
>>    Public Property Handler() As ExceptionHandler
>>        Get
>>            Return pHandler
>>        End Get
>>        Set(ByVal Value As ExceptionHandler)
>>            If Value Is Nothing Then _
>>                pHandler = AddressOf PrivateHandler _
>>            Else _
>>                pHandler = Value
>>        End Set
>>    End Property
>>
>>    Private Sub PrivateHandler(ByVal ex As Exception, ByVal OneTimeExtra
>> As String)
>>        ..... <intrinsic handling>
>>    End Sub
>> End Class
>> ===== END CODE ================================================
>>
>> Thanks in advance,
>> - Arthur Dent.
>>
>
>
Author
7 Oct 2005 12:44 PM
cody
The DesignerSerialisationVisibility attribute will have only affect in
designmode that, is when you open the component in designmode the property
cannot be modified from designmode.


Show quote
"Arthur Dent" <hitchhikersguideto-n***@yahoo.com> schrieb im Newsbeitrag
news:%23Yvl2qayFHA.1032@TK2MSFTNGP12.phx.gbl...
>
> The only thing which i would see as a problem with using events is that
> i want the custom handler to completely supplant the built-in handler
> (if a custom one is specified). If i used events, and the consumer handled
> the event, then it would happen *in addition to* the built in handler as
> opposed
> to *instead of*, no?
>
> Thanks for the response. The DesignerSerialisationVisibility, will that
> have any effects
> on the component as far as it "forgetting" who the current handler-routine
> is?
>
> Thanks again.
>
>
> "cody" <deutron***@gmx.de> wrote in message
> news:uB8BHTYyFHA.3864@TK2MSFTNGP12.phx.gbl...
>> You should use events instead of delegates directly for this so the
>> problem should go away.
>> If not, you can mark the delegate property with the
>> <DesignerSerialisationVisibility(DesignerSerialisationVisibility.Hidden)>
>> attribute.
>>
>>
>> "Arthur Dent" <hitchhikersguideto-n***@yahoo.com> schrieb im Newsbeitrag
>> news:e3fOSoVyFHA.3812@TK2MSFTNGP09.phx.gbl...
>>> Hello all...
>>>
>>> I have a component which i wrote, which is used for automatically
>>> emailing errors, so that when an app (usually a website) goes into
>>> production, i automatically get emailed about any exceptions which occur
>>> on the site. A friend wanted to use the same thing but have the ability
>>> to override the OnError action, because their mail handler had to be
>>> handled in an unusual manner.
>>>
>>> To accomodate his need, i added a delegate definition to the component.
>>> Now it allows the user to either accept the intrinsic behaviour or
>>> replace it with their own... for an odd email handler, or logging or
>>> simply messageboxing the user.
>>>
>>> The only problem is now i cannot drag the component onto a form designer
>>> anymore, because it says the Handler property is not serializable.
>>> Is there any way that i can get around that? Isnt a delegate basically a
>>> function pointer? which is basically an Int? which should be
>>> serializable?
>>>
>>> My code (partial/relevant) is as follows:
>>> ===== BEGIN CODE ==============================================
>>> Public Class ErrorHandler
>>>    Inherits System.ComponentModel.Component
>>>
>>>    Delegate Sub ExceptionHandler(ByVal ex As Exception, ByVal
>>> OneTimeExtra As String)
>>>    Private pHandler As ExceptionHandler = AddressOf PrivateHandler
>>>
>>>    Public Property Handler() As ExceptionHandler
>>>        Get
>>>            Return pHandler
>>>        End Get
>>>        Set(ByVal Value As ExceptionHandler)
>>>            If Value Is Nothing Then _
>>>                pHandler = AddressOf PrivateHandler _
>>>            Else _
>>>                pHandler = Value
>>>        End Set
>>>    End Property
>>>
>>>    Private Sub PrivateHandler(ByVal ex As Exception, ByVal OneTimeExtra
>>> As String)
>>>        ..... <intrinsic handling>
>>>    End Sub
>>> End Class
>>> ===== END CODE ================================================
>>>
>>> Thanks in advance,
>>> - Arthur Dent.
>>>
>>
>>
>
>
Author
10 Oct 2005 10:51 PM
Arthur Dent
Thanks for the help, worked beautifully.

Show quote
"cody" <deutron***@gmx.de> wrote in message
news:ewSJKzzyFHA.3320@TK2MSFTNGP14.phx.gbl...
> The DesignerSerialisationVisibility attribute will have only affect in
> designmode that, is when you open the component in designmode the property
> cannot be modified from designmode.
>
>
> "Arthur Dent" <hitchhikersguideto-n***@yahoo.com> schrieb im Newsbeitrag
> news:%23Yvl2qayFHA.1032@TK2MSFTNGP12.phx.gbl...
>>
>> The only thing which i would see as a problem with using events is that
>> i want the custom handler to completely supplant the built-in handler
>> (if a custom one is specified). If i used events, and the consumer
>> handled
>> the event, then it would happen *in addition to* the built in handler as
>> opposed
>> to *instead of*, no?
>>
>> Thanks for the response. The DesignerSerialisationVisibility, will that
>> have any effects
>> on the component as far as it "forgetting" who the current
>> handler-routine is?
>>
>> Thanks again.
>>
>>
>> "cody" <deutron***@gmx.de> wrote in message
>> news:uB8BHTYyFHA.3864@TK2MSFTNGP12.phx.gbl...
>>> You should use events instead of delegates directly for this so the
>>> problem should go away.
>>> If not, you can mark the delegate property with the
>>> <DesignerSerialisationVisibility(DesignerSerialisationVisibility.Hidden)>
>>> attribute.
>>>
>>>
>>> "Arthur Dent" <hitchhikersguideto-n***@yahoo.com> schrieb im Newsbeitrag
>>> news:e3fOSoVyFHA.3812@TK2MSFTNGP09.phx.gbl...
>>>> Hello all...
>>>>
>>>> I have a component which i wrote, which is used for automatically
>>>> emailing errors, so that when an app (usually a website) goes into
>>>> production, i automatically get emailed about any exceptions which
>>>> occur on the site. A friend wanted to use the same thing but have the
>>>> ability to override the OnError action, because their mail handler had
>>>> to be handled in an unusual manner.
>>>>
>>>> To accomodate his need, i added a delegate definition to the component.
>>>> Now it allows the user to either accept the intrinsic behaviour or
>>>> replace it with their own... for an odd email handler, or logging or
>>>> simply messageboxing the user.
>>>>
>>>> The only problem is now i cannot drag the component onto a form
>>>> designer anymore, because it says the Handler property is not
>>>> serializable.
>>>> Is there any way that i can get around that? Isnt a delegate basically
>>>> a function pointer? which is basically an Int? which should be
>>>> serializable?
>>>>
>>>> My code (partial/relevant) is as follows:
>>>> ===== BEGIN CODE ==============================================
>>>> Public Class ErrorHandler
>>>>    Inherits System.ComponentModel.Component
>>>>
>>>>    Delegate Sub ExceptionHandler(ByVal ex As Exception, ByVal
>>>> OneTimeExtra As String)
>>>>    Private pHandler As ExceptionHandler = AddressOf PrivateHandler
>>>>
>>>>    Public Property Handler() As ExceptionHandler
>>>>        Get
>>>>            Return pHandler
>>>>        End Get
>>>>        Set(ByVal Value As ExceptionHandler)
>>>>            If Value Is Nothing Then _
>>>>                pHandler = AddressOf PrivateHandler _
>>>>            Else _
>>>>                pHandler = Value
>>>>        End Set
>>>>    End Property
>>>>
>>>>    Private Sub PrivateHandler(ByVal ex As Exception, ByVal OneTimeExtra
>>>> As String)
>>>>        ..... <intrinsic handling>
>>>>    End Sub
>>>> End Class
>>>> ===== END CODE ================================================
>>>>
>>>> Thanks in advance,
>>>> - Arthur Dent.
>>>>
>>>
>>>
>>
>>
>
>

AddThis Social Bookmark Button