Thursday, January 06, 2005
« Indigo and SOA in San Francisco | Main | C# event issue resolved »

Several months ago I posted an entry about the new VB syntax for manual declaration of events – specifically showing how it can be used to solve today’s issue with attempted serialization of nonserializable event listeners.

 

Subsequent to that post, I posted a follow-up with a better version of the code, thanks to input from a reader.

 

At the moment I am working through some eventing issues in both VB and C#, and I’ve found what appears to be a troubling limitation in C#.

 

In the new VB manual declaration scheme we have the ability to manually raise the event using the backing field. This allows me to have two backing fields - one serialized and one not as shown in my follow-up post. This is really nice, because it means we can retain serializable delegate references, while dropping nonserializable references.

 

Unfortunately, it doesn’t appear that the C# syntax allows us to control how the backing field is invoked. It appears that only one backing field is possible, and it is invoked automatically such that we don't have control over the invocation.

 

If we can’t control the invocation, then we can’t invoke both the serialized and nonserialized set of delegates. This will force the C# code to treat all the delegates as nonserialized, even those that could be serialized.

 

Of course I’m researching this for CSLA .NET 2.0. Wouldn’t it be a joke if this time the C# framework had to have some VB code (since last time it was the other way around)?

 

Anyone have any insight into a solution on the C# side?