Compiler Error: "is inaccessible due to its protection level" - nested class' event won't compile.

Hi,

The following code does not compile in Unity (checked in 4.7.1f1 and 5.3.4f1) but compiles in regular .net 3.5 project:

using System;

public class Test<T>
{
    private class Inner
    {
        public event Action onAction;
    }

    public void Foo()
    {
        var inner = new Inner();
        inner.onAction += inner_onAction;
    }

    void inner_onAction()
    {
        throw new NotImplementedException();
    }
}

If the class has no generic parameter than it compiles fine. Also if the reserved keyword “event” is removed than it also compiles. Changing Inner class access modifier to public has not effect.

I’m not sure if this qualifies for a bug report - I guess that it’s the issue with mono compiler. I’ve checked Microsoft .net and Xamarin compilers and both compile this piece of code without any errors.

I figured that this problem can be easily avoided by introducing non generic class version:

using System;

public class Test<T>
{
    private class Inner<T>
    {
        public event Action onAction;
    }

    private class Inner : Inner<T>
    { }

    public void Foo()
    {
        var inner = new Inner();
        inner.onAction += inner_onAction;
    }

    void inner_onAction()
    {
        throw new NotImplementedException();
    }
}