3

In my C# solution I've got multiple projects.

One of them is OdulaProject (XNA WP7 game). (I) The primary project is Editor (WinForms app) (II)

In (I) is this piece of code:

namespace OdulaProject.GameCore.Resources
{
    public class MyLevel
    {
        // TODO: remove!!!
        public static Vector3 GetFieldPosition(Point coordinates)
        {
            return new Vector3(coordinates.X * MyGameConstants.FieldSize.X, coordinates.Y * MyGameConstants.FieldSize.Y, 0);
        }
    }
}

In (II) I've got a reference to (I) and this piece of code:

using OdulaProject.GameCore.Resources;

...

MyLevel.GetFieldPosition(new Point(0, 0));

And I'm still getting en error:

'OdulaProject.GameCore.Resources.MyLevel' is inaccessible due to its protection level

Steve H
  • 5,479
  • 4
  • 20
  • 26
  • 3
    did you try to rebuild your whole solution? – shriek May 25 '13 at 16:09
  • 1
    Are you sure you don't have a duplication of OdulaProject.GameCore.Resources.MyLevel by mistake? – Liel May 25 '13 at 16:10
  • Yeah, tried to rebuild with no success... The duplicate? Guess it should be duplicates free. But I'm sharing OdulaProject project between two solutions (game solution and editor solution) - could it be a problem? – user2420644 May 25 '13 at 16:16
  • what happens when you comment out your MyLevel class an try to rebuild? and if you still get the same error, where does 'Go to Definition' take you? – shriek May 25 '13 at 16:21
  • 'Go to Definition' takes me directly to the code mentioned above. And when I comment the whole class out, I still get the same error while rebuilding (inaccessible due to its protection level). – user2420644 May 25 '13 at 16:24
  • And when I try to 'Go to the definition' while the whole class is commented out I got an error "Cannot navigate to 'MyLevel'." – user2420644 May 25 '13 at 16:33
  • Solution founded: In solution I had got other similar problems (some classes were inaccessible due to its protection level...) and in one of these (public) classes I used public list of internal classes. – user2420644 May 25 '13 at 16:54
  • 1
    Making class public should solve this. See http://stackoverflow.com/questions/3595380/c-sharp-compile-error-x-is-inaccessible-due-to-its-protection-level – Lex Podgorny Nov 23 '13 at 12:36
  • Is MyLevel an instance of the class MyLevel? If so your issue is that you are accessing a static method through an instance of the class. Other then that I see no reason for the code to not be working. – ClassicThunder Jun 06 '14 at 17:59

1 Answers1

0

This may seem tricky, but in a solution with multiple projects, some might require public that others don't. Adding public liberally, to the offending class/static innards can help debug the missing accessibility.

It goes without saying, that these should all be re-evaluated post-hoc.

Gant Laborde
  • 6,484
  • 1
  • 21
  • 30