7

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.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Steve Chadbourne
  • 6,873
  • 3
  • 54
  • 82

2 Answers2

16

probably your GetSetting function must fully match GetSettingDelegate signature:

Private Function GetSetting(ByVal key As String) as String
max
  • 33,369
  • 7
  • 73
  • 84
7

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
Jeff Paulsen
  • 2,132
  • 1
  • 12
  • 10