Comparing .NET delegates
I'm having some problems comparing delegates. In all sample projects I
create, I can't get the problem to occur, but there is definitely a problem
with my production code.
I can't give all the code, as there's simply too much, but here's the
I have a connection object which connects to a custom back-end server of one
type or another. Clients of this connection object send requests via a
method (e.g. connection.SendRequest()) and one of parameters to this call is
a callback delegate.
At a later point, the client may attempt to cancel all the requests specific
to the delegate that was passed in. It's in this method that I'm doing the
delegate comparisons. Consistently, the delegates never match, so the
requests can't be cancelled.
In the client code, I've tried passing in the method name directly or a
delegate instance, created with the method as a parameter. I get the same
results either way.
When debugging, I notice something strange, and no doubt the cause of the
The stored delegate refers to the actual method to call:
.Method: the actual method name
.Target: the actual class name where the method resides
...but the delegate passed in, refers to an Invoke method:
.Target: the delegate type!
So, I understand why the comparison is failing. They don't appear to be the
same delegate at all! But I don't understand why the passed in delegate
refers to the Invoke method, instead of the actual target method.
Can someone explain to me what's going on? And moreover, does anyone have a
solution to the problem?
By Phil Weber in forum .NET
Last Post: 10-01-2003, 01:00 AM
Last Post: 02-28-2003, 04:43 PM
By Patrick Troughton in forum .NET
Last Post: 02-12-2003, 10:31 AM
By AutomatedQA Corp in forum .NET
Last Post: 03-20-2002, 06:28 AM
By Seth Grossman [MSFT] in forum .NET
Last Post: 02-28-2002, 02:44 PM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL