views:

127

answers:

2

Porting an application from C# (1.1 framework) to VB.NET (3.5 framework), and I have this one last event based issue I cannot get my head around.

This is the original C# code

public delegate void SpecialEventHandler(object sender,SpecialEventArgs e);
public event SpecialEventHandler SpecialEvent = null;

_SpecialLogWriter  SpecialWriter = new _SpecialLogWriter(this.SpecialEvent);

This is the converted VB.NET code

Public Delegate Sub SpecialEventHandler(ByVal sender as Object, ByVal e as SpecialEventArgs)
Public Event SpecialEvent as SpecialEventHandler

Dim SpecialWriter as New _SpecialLogWriter(Me.SpecialEvent)

The SpecialLogWriter constructor is expecting a SpecialEventHandler, but the Me.SpecialEvent in the constructor of SpecialLogWriter gives me the error message that this is an event and cannot be called directly.

Am I missing another delegate, or is this just one of this declaration issues between the languages?

A: 

You say the constructor expects event handler but you're passing an event, not event handler. Shouldn't you use:

Dim SpecialWriter as New _SpecialLogWriter(New SpecialEventArgs())
Hugo Riley
A: 

I am forced to wonder if the original code worked properly to begin with. I simply removed the event tag from the SpecialEvent declaration, and all seems to be working at this point.

Jeff.Crossett