I am trying to take a library Coded for .NET 4 and recompile it to use .NET 3.5 Client. The library is available at https://github.com/cshivers/IrcClient-csharp/tree/master/IrcClient-csharp
This is the block of Code in my program that gets an error when Calling Irc.ChannelMessage in the external library.
Private Sub irc_ChannelMessage(Channel As String, User As String, Message As String) Handles irc.ChannelMessage
rtbOutput.Clear()
rtbOutput.Text = Message
If rtbOutput.Text.StartsWith("!Listen ") Then
Dim s As String = rtbOutput.Text
Dim pars As New List(Of String)(s.Split(" "c))
CheckParams(pars)
End If
End Sub
The Library works for my program when it is set to use .NET 4, however when I set it to use .Net 3.5 Client it returns the error below
Error 4 Method 'Private Sub irc_ChannelMessage(Channel As String, User As String, Message As String)' cannot handle event 'Public Event ChannelMessage(sender As Object, e As TechLifeForum.ChannelMessageEventArgs)' because they do not have a compatible signature.
It seems That once I compile it for .NET 3.5 The IrcClient.cs can't translate it to EventArguments.cs properly...
in IrcClient.cs We are calling
public event EventHandler<ChannelMessageEventArgs> ChannelMessage = delegate { };
and that should then call This from EventArguments.cs:
public class ChannelMessageEventArgs : EventArgs
{
public string Channel { get; internal set; }
public string From { get; internal set; }
public string Message { get; internal set; }
public ChannelMessageEventArgs(string Channel, string From, string Message)
{
this.Channel = Channel;
this.From = From;
this.Message = Message;
}
}
However it will only work in .NET 4 any IDEAS?
When setting up an event handler (Handles
keyword), the signature of the method (in other words, the variables passed to the method) must match the signature of the event.
Your event's signature is (C#):
EventHandler<ChannelMessageEventArgs> ChannelMessage
(vb.net):
EventHandler(EventArgs as ChannelMessageEventArgs)
You are incorrectly trying to handle this event with the following signature:
irc_ChannelMessage(Channel As String, User As String, Message As String)
These three variables are contained within the ChannelMessageEventArgs class, and passed together, therefore you can change your event handling method to:
Private Sub irc_ChannelMessage(EventArgs As ChannelMessageEventArgs) Handles irc.ChannelMessage
rtbOutput.Clear()
rtbOutput.Text = EventArgs.Message
If rtbOutput.Text.StartsWith("!Listen ") Then
Dim s As String = rtbOutput.Text
Dim pars As New List(Of String)(s.Split(" "c))
CheckParams(pars)
End If
End Sub