Max
Max

Reputation: 13388

Inconsistent accessibility using Delegates

I'm trying to send a string from form SettingsMenu to my Main form using a Delegate, the structure is as shown below:

Delegate at SettingsMenu form:

delegate void ClocknameReceivedEventHandler(object sender, SettingsMenu.ClocknameReceivedEventArgs e);

Internal class ClocknameReceivedEventArgs within the SettingsMenu class:

public partial class SettingsMenu : Form
{
    internal class ClocknameReceivedEventArgs : EventArgs
    {
        string _clockname;
        public string Clockname
        {
            get { return _clockname; }
        }

        public ClocknameReceivedEventArgs(string clockname)
        {
            _clockname = clockname;
        }
    }
}

And a bit more down in code in SettingsMenu:

public event ClocknameReceivedEventHandler ClocknameReceived;

// Invoke the Changed event; called whenever list changes
protected void OnClocknameReceived(SettingsMenu.ClocknameReceivedEventArgs e)
{
    ClocknameReceived(this, e);
}

I catch the incoming data from SettingsMenu on my Main form using the following Event:

_settings.ClocknameReceived += new ClocknameReceivedEventHandler(ClockClocknameReceived);

The method on my Main form that actually received the string from SettingsMenu:

private void ClockClocknameReceived(object sender, SettingsMenu.ClocknameReceivedEventArgs e)
{
    string ClockName;
    ClockName = e.Clockname;
    lblClockname.Text = ClockName;
}

Now I get the following errors at the SettingsMenu class:

Error   2   Inconsistent accessibility: parameter type 'LivePigeonClient.Forms.SettingsMenu.ClocknameReceivedEventArgs' is less accessible than method 'LivePigeonClient.Forms.SettingsMenu.OnClocknameReceived(LivePigeonClient.Forms.SettingsMenu.ClocknameReceivedEventArgs)'    D:\SVN\sentul\Livepigeonflights\trunk\LivePigeonClientSolution\LivePigeonClient\Forms\SettingsMenu.cs   54  24  LivePigeonClient

And

Error   1   Inconsistent accessibility: field type 'LivePigeonClient.Forms.ClocknameReceivedEventHandler' is less accessible than field 'LivePigeonClient.Forms.SettingsMenu.ClocknameReceived' D:\SVN\sentul\Livepigeonflights\trunk\LivePigeonClientSolution\LivePigeonClient\Forms\SettingsMenu.cs   51  52  LivePigeonClient

Can anybody tell me what I did wrong?

Upvotes: 1

Views: 7754

Answers (4)

Sanu Uthaiah Bollera
Sanu Uthaiah Bollera

Reputation: 937

If you are using public access specifier to the delegate then, remove it.! It worked great for me.!

Upvotes: 0

Max
Max

Reputation: 13388

I needed to use a public delegate and a public class to solve the problem.

Upvotes: 13

Buh Buh
Buh Buh

Reputation: 7546

Your event args are marked as internal, meaning that it is not shared outside of your assemby:

internal class ClocknameReceivedEventArgs

But then you use it on a method which is maked as protected (which is available outside the assembly):

protected void OnClocknameReceived(SettingsMenu.ClocknameReceivedEventArgs e)

If the compiler allowed this then how would anyone be supposed to call your method if they can't create the parameter?

To fix, perhaps change them to both be public or both protected, or both internal, depending on how you want this to be used.

Upvotes: 2

b_meyer
b_meyer

Reputation: 604

Yeah, just switch the access modifier to public and you should be fine ...

Upvotes: 0

Related Questions