0

I found this web site: How to use a Class from one C# project with another C# project

however, the class that I want to access is the following. I am using the namespace to access the value but does not work. Project B

namespace Elettric80.LgvManager
{
    class ConveyorStation : MachineStation 
    {
         public ConveyorStation(LGVManager lgvManager, string name, uint depth, 
                                uint width, uint maxLevels)
            : base(lgvManager, name, depth, width, maxLevels)
         {
         }
    }
}

This is how I am trying to access: project A

using Elettric80.LgvManager;

private ConveyorStation conveyorStation;

txtvalue.text = conveyorStation.value.ToString();

thank you

Community
  • 1
  • 1

2 Answers2

3
namespace Elettric80.LgvManager
{
    class ConveyorStation : MachineStation // compiler is assuming you meant internal class
    {
      ...
    }
}

You need to make Conveyor station a 'public' class. Leaving it unspecified makes the compiler assume that you meant 'internal' class, which only allows access from within the same assembly. Change it to:

namespace Elettric80.LgvManager
{
    public class ConveyorStation : MachineStation 
    {
      ...
    }
}

and your problem should be solved.


More completely; the different levels of access levels can be found here (MSDN - Accessibility Levels).. The relevant quote for this problem:

Top-level types, which are not nested in other types, can only have internal or public accessibility. The default accessibility for these types is internal.

Az Za
  • 394
  • 1
  • 9
0

Specify the access modifier of the ConveyorStation class to public since by default the access modifier is internal (Not accessible from other assemblies).

Additionally, Make sure you have project reference:

Right click on project references and add reference to the project that has the value you want to access to. https://i.stack.imgur.com/6l5p4.png

Aviran Cohen
  • 5,581
  • 4
  • 48
  • 75