Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How fix AddressOf requires a relaxed conversation to the delegate error

Sorry, this is a mix of C# and VB.Net

I have a C# class with with 2 delegates:

public delegate string GetSettingDelegate(string key);
public event GetSettingDelegate GetSettingEvent;

public delegate void SetSettingDelegate(string key, string value);
public event SetSettingDelegate SetSettingEvent;

In a VB class I add handlers to the event:

AddHandler _gisCtrl.SetSettingEvent, AddressOf SetSetting
AddHandler _gisCtrl.GetSettingEvent, AddressOf GetSetting

When I try and remove the handlers:

RemoveHandler _gisCtrl.SetSettingEvent, AddressOf SetSetting
RemoveHandler _gisCtrl.GetSettingEvent, AddressOf GetSetting

SetSetting is OK but GetSetting throws a warning:

The AddressOf expression has no effect in this context because the method arguments to AddressOf requires a relaxed conversation to the delagate type of the event.

Here are the methods

Private Sub SetSetting(ByVal key As String, ByVal value As String)
    KernMobileBusinessLayer.[Global].Settings.SetValue(key, value)
End Sub

Private Function GetSetting(ByVal key As String)
    Return KernMobileBusinessLayer.[Global].Settings.GetString(key)
End Function

Any idea how to fix this and why it is thrown in the first place? The 2 delegates/events/methods look similar enough that I don't know why one is OK and one throws a warning.

like image 262
Steve Chadbourne Avatar asked May 23 '11 22:05

Steve Chadbourne


2 Answers

probably your GetSetting function must fully match GetSettingDelegate signature:

Private Function GetSetting(ByVal key As String) as String
like image 99
max Avatar answered Oct 23 '22 23:10

max


your vb code:

Private Function GetSetting(ByVal key As String)

doesn't match the C# delegate definition:

public delegate string GetSettingDelegate(string key);

you should specify a return type in your VB implementation, like this:

Private Function GetSetting(ByVal key As String) As String
like image 45
Jeff Paulsen Avatar answered Oct 24 '22 00:10

Jeff Paulsen