Access a value from one project in another

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

Upvotes: 0

Views: 1694

Answers (2)

Aviran Cohen
Aviran Cohen

Reputation: 5691

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.sstatic.net/6l5p4.png

Upvotes: 0

Az Za
Az Za

Reputation: 394

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.

Upvotes: 3

Related Questions