can't reference class from another project of the same solution

后端 未结 3 1266
囚心锁ツ
囚心锁ツ 2021-01-28 16:43

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

相关标签:
3条回答
  • 2021-01-28 17:07

    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";
        }
     }
    
    0 讨论(0)
  • 2021-01-28 17:12

    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.

    0 讨论(0)
  • 2021-01-28 17:19

    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";
    
    0 讨论(0)
提交回复
热议问题