jax
jax

Reputation: 38623

Inconsistent accessibility: parameter type for generic c# interface

I am getting the following error in VisualStudio

Inconsistent accessibility: parameter type 'mynamespace.ProgressChangedEvent' is less accessible than method 'mynamespace.StartScreen.ReceiveUpdate(mynamespace.ProgressChangedEvent)'

My interface looks like this

public interface IObserver<T>
{
     void ReceiveUpdate(T ev);
}

My Events class looks like this

namespace mynamespace
{
//The event interface
interface Event {}

//Concrete Event
class ProgressChangedEvent : Event
{
    private int fileCount = 0;
    private int filesProcessed = 0;

    public ProgressChangedEvent(int fileCount, int filesProcessed)
    {
        this.fileCount = fileCount;
        this.filesProcessed = filesProcessed;
    }

    public int FileCount
    {
        get{return fileCount;}
        set{fileCount = value;}
    }

    public int FilesProcessed
    {
        get { return filesProcessed; }
        set { filesProcessed = value; }
    }


    }
}

The class is a form, it looks like this

namespace mynamespace
{
  public partial class StartScreen : Form, IObserver<ProgressChangedEvent>
  {


   /*
    * Lots of form code...
    */

    #region IObserver<ProgressChangedEvent> Members

    public void ReceiveUpdate(ProgressChangedEvent ev)
    {
        throw new Exception("The method or operation is not implemented.");
    }

    #endregion
    }


}

The method ReceiveUpdate is highlighted and the above error is shown.

Upvotes: 2

Views: 4472

Answers (2)

BrokenGlass
BrokenGlass

Reputation: 160922

You have to make your class public:

class ProgressChangedEvent : Event
{

should be

public class ProgressChangedEvent : Event
{

Since your public method ReceiveUpdate() is expecting a variable of type ProgressChangedEvent, that class must be public too so it can actually be used (from outside your assembly) - that's why you get that error.

Upvotes: 6

Jon
Jon

Reputation: 979

You need to make your ProgressChangedEvent class public.

Upvotes: 1

Related Questions