Error__Inconsistent accessibility: field type 'trial2.logfile' is less accessible than field 'trial2.Form1.loginfo'_ RRS feed

  • Question

  • namespace trial2
        public partial class Form1 : Form
            serial_function serial_f = new serial_function();  // creating class Serial function
            Prase_Calibration_file prase_file = new Prase_Calibration_file();  // creating class prase calibration file
            public logfile loginfo = new logfile();   // creating class logfile as public

            int tunning_steps = 0;
            double tunning_wavelength = 0;
            bool Scanning_Run_Start = false;
            int Get_Cur_Steps_Enable = 0;
            double scaning_fin_wavelength = 0;
            double scaning_ini_wavelength = 0;
            int ini_step = 0;
            int Sscn = 0;
            int scanning_count = 0;
            public string old_setps = "-1";
            public string openportname;
            public int send_cmd_count = 0;
            Thread monitor;
            bool adjust_change_flag = false;
            public Form1()





    namespace trial2
          public class logfile

            private string sLogFormat;
            private string sErrorTime;

            public logfile()
                //sLogFormat used to create log files format :
                // dd/mm/yyyy hh:mm:ss AM/PM ==> Log Message

                //this variable used to create log filename format "
                //for example filename : ErrorLogYYYYMMDD
                string sYear = DateTime.Now.Year.ToString();
                string sMonth = DateTime.Now.Month.ToString();
                string sDay = DateTime.Now.Day.ToString();
                sErrorTime = sYear + sMonth + sDay;
    Save log information
            public void Loginfo(string sPathName, string sErrMsg)
                sLogFormat = DateTime.Now.ToShortDateString().ToString() + " " + DateTime.Now.ToLongTimeString().ToString() + " ==> ";
                StreamWriter sw = new StreamWriter(sPathName + sErrorTime + ".txt", true);
                sw.WriteLine(sLogFormat + sErrMsg);

        Why am i getting Inconsistent accessibility error? Loginfo is used in all 3 classes  hence i have declared the class as public. I dont know what mistake i am doing. Any help is greatly appreciated. Thank you!
    Monday, July 22, 2019 2:58 PM

All replies

  • Which line is the issue on?

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Monday, July 22, 2019 3:56 PM
  • None of the code you posted is invalid. Beyond styling issues like using camel casing for types (.NET does Pascal) and making a field in your form class public (they should pretty much always be private) there isn't any place in the code that accessibility would come into play.

    Post where you're actually using this code and the line where the compiler error is along with the exact error message as Karen requested.

    Michael Taylor http://www.michaeltaylorp3.net

    Monday, July 22, 2019 9:07 PM