0

My solution contains several projects including Commons and TerminatorConsole2. Now I want to refer Commons.Constants class from TerminatorConsole2.Utils.Constants file:

namespace TerminatorConsole2.Utils
{
    class Constants
    {
        public const string MANAGEMENT_CONSOLE_ADDRESS =
            Commons.Constants.USE_EXTRA_WCF_INSTANCE ?
                "net.pipe://localhost/xxx" :
                "net.pipe://localhost";

But I receive "Cannot resolve symbol" on "Commons". Adding "using Commons" doesn't help, I receive same error.

Why one project can not use class from another project of the same solution?

UPD Adding Constants class. However I already use it from one another project so I think this class is OK:

namespace Commons
{

public class Constants
{
    public const int MAX_INSTRUMENTS_NUMBER_IN_SYSTEM = 200;
    public const bool USE_EXTRA_WCF_INSTANCE = true;
}

}
1

3 Answers 3

2

By default the scope of class is internal which mean could be accessed within that assembly Make the class public in order to make it accessible to other assemblies. More about access modifiers Also make sure you added the reference of assembly you are reffering.

Change

class Constants
    {
        public const string MANAGEMENT_CONSOLE_ADDRESS =
            Commons.Constants.USE_EXTRA_WCF_INSTANCE ?
                "net.pipe://localhost/xxx" :
                "net.pipe://localhost";

To

public class Constants
    {
        public const string MANAGEMENT_CONSOLE_ADDRESS =
            Commons.Constants.USE_EXTRA_WCF_INSTANCE ?
                "net.pipe://localhost/xxx" :
                "net.pipe://localhost";
Sign up to request clarification or add additional context in comments.

4 Comments

is there a difference between the two? I think you missed the public class modifier
here you will find about public and other access modifiers msdn.microsoft.com/en-us/library/ms173121.aspx
i shouldn't declare this class public. i just need to add reference as jeroenh said
I thought you added reference, Can you access this class in other assembly without making it public?
0

Try this: add public to class Constants

namespace TerminatorConsole2.Utils
{
    public class Constants
    {
        public const string MANAGEMENT_CONSOLE_ADDRESS =
            Commons.Constants.USE_EXTRA_WCF_INSTANCE ?
                "net.pipe://localhost/xxx" :
                "net.pipe://localhost";
    }
 }

1 Comment

did you add the reference to your project - hope you didn't forget that? Is it a console application or web application?
0

jeroenh correctly answered the question in a comment... I needed to add a reference.

I didn't need to declare the class public, since only class which is used should be public. class that "using" doesn't have to be public.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.