The method (insert my method) was referenced without quotation marks

58 views Asked by At

So this is with visual studio 2003. The code works perfect on higher frameworks however I need it in 1.1 so this is my only option. Also, the programs in german so the actual message was "Auf die methode (mymethod) wurde ohne anführungszeichen verwiesen". The code and everything is on a seperate PC so I can retrieve it if necessary but unfortunately no copy paste so for now i'm just writing as my main question how on earth is that even an error? Adding quotations doesn't work and gives the expected error complaining you can't implicitly convert method type to string. The line it failed on was FileSystemWatcher += fileSystemWatcher_Changed Theres a bunch more errors which I've managed to work around and more to fix however this is the only one thats truly stumpt me and any guidence would be useful. I've trie using ' as quotations around it as well as * on either side. I've tried passing arguments which it uses which was of no help and honestly don't even know what else to try as I'm new to coding and it worked perfect on framework 2.0. Just not in this german 2003 1.1 framework..

Any help is kindly appreciated!

edit: Heres the related code to the error

private static void GetCurrentJob()
        {
            //This gets the file
            string CurrentJobPath = @"C:\LuK\Master\Daten\dnocontainer.cfg";

            //This makes it so it only reads the 5th line of the notepad and ignore everything else
            //string line = File.ReadLines(CurrentJobPath).Skip(4).Take(1).First();
            string[] lines = File.ReadAllLines(CurrentJobPath);
            string line = lines[4];

            //This is getting rid of all parts of the line I don't care about
            line = line.Replace(" ", "").Replace("(STRING)Dno=", "").Replace("\"", "").Replace(";", "");

            //This isn't necessary but I like it okay
            JobName = line;
            //Testing To prove its behaving
            Console.WriteLine(JobName);
            //This is making a path to the exact folder for the job currently running
            AreaOfMonitor = @"C:\LuK\Master\Zeichnungsdaten\" + JobName;
            Console.WriteLine(AreaOfMonitor);
        }

        private static void ProgramSwapMonitor(string ProgramChange)
        {
            // Create a new FileSystemWatcher and set its properties.
            FileSystemWatcher watcher = new FileSystemWatcher();
            watcher.Path = ProgramChange;

            /* Watch for changes in LastAccess and LastWrite times, and 
               the renaming of files or directories. */

            watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                | NotifyFilters.FileName | NotifyFilters.DirectoryName;

            // Only watch this specific file
            watcher.Filter = "dnocontainer.cfg";

            // Add event handlers.
            watcher.Changed += new FileSystemEventHandler(OnChanged);
            watcher.Created += new FileSystemEventHandler(OnChanged);
            watcher.Deleted += new FileSystemEventHandler(OnChanged);
            watcher.Renamed += new RenamedEventHandler(OnRenamed);

            // Begin watching.
            watcher.EnableRaisingEvents = true;
        }

        // Define the event handlers.
        private static void OnChanged(object source, FileSystemEventArgs e)
        {
            // Specify what is done when a file is changed, created, or deleted.
            Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
            Console.WriteLine(Spacer);

            //This disables the directory monitor, then changes the active job in its memory, then restarts the directory monitor so it can now monitor the new location, then removes the old watcherChanged instance so theres no duplicates.
            fileSystemWatcher.EnableRaisingEvents = false;
            GetCurrentJob();
            MonitorDirectory(path);
            fileSystemWatcher.Changed -= FileSystemWatcher_Changed;

public static void MonitorDirectory(string path)
        {
            //fileSystemWatcher.EnableRaisingEvents = false;
            path = AreaOfMonitor;

            //Declaring variables outside the catch for use of error handling
            string ErrorHandlingPathName = path;
            string ErrorPathNameMaster = "JobNameError";
            string Unlikely = "";
            string errorpath = @"D:\JobEditsSaved\" + ErrorPathNameMaster + ".txt";
            string PathError = "This file isn't in the directory, does a new job need adding?";
            string Aidpath = @"D:\JobEditsSaved\CODEISSUES.txt";
            int retryName = 0;
            int NewNameCount = 0;

            //Trys to do the normal function of beginning monitoring of path extracted from the dnocontainer
            //If the file extracted doesn't have a corrosponding folder, rather than crash the program we write an error log which
            //In the backup location writes a textfile saying its had this problem and writes the name of the job it couldn't find
            //If this exceptions been thrown, the name of the errorTextFile I'm creating would already exist, so I'm doing a simple
            //Counter which will add a number to the end of the error file name if it exists already.
            try
            {
                //Trys code we want to work
                fileSystemWatcher.Path = path;
            }
            catch (IOException ex)
            {
                //Both these catches do the exact same thing but different exceptions. However, the exceptions are for effectively the same  thing (dir not exist)
                //It will try to write an error log, if an error logs been made before, it adds 1 to its name, trys again and repeats this pricess 5000 times.
                //If theres serious issues leading to errors then it will make a file saying to get me to look at code cause god almighty something major must have happened.
                while (retryName < 5000)
                {
                    if (!File.Exists(errorpath))//check if error log file is existing
                    {
                        PathError = PathError + ex;
                        File.WriteAllText(errorpath, PathError);
                        Console.WriteLine(PathError);
                        retryName = 0;
                        NewNameCount = 0;
                        break;
                    }
                    else if (errorpath.Length <= 250)//checks that the new error log file name its giving is less than max characters for a file in wondows
                    {
                        string ErrorPathName = ErrorPathNameMaster;
                        NewNameCount++;
                        retryName++;
                        ErrorPathName = ErrorPathNameMaster + Convert.ToString(NewNameCount);
                        Console.WriteLine("ErrorFile Name exits. Attempting new file name -" + ErrorPathName);
                        errorpath = @"D:\JobEditsSaved\" + ErrorPathName + ".txt";
                    }
                    else if (errorpath.Length > 250)//if its more than max characters lets stop the numbers, reset them, then change part of the name and run again. Allowing double the error logs
                    {
                        NewNameCount = 0;
                        retryName++;
                        NewNameCount++;
                        Unlikely = "JobNameError,ClearSomeErrorsOut" + Convert.ToString(NewNameCount);
                        errorpath = @"D:\JobEditsSaved\" + Unlikely + ".txt";
                    }
                    else //at this point theres over 500 errors thats occured. Someone should have analyised it and seen a few and followed it up, nevermind over 500. Only scenario I see where this could happen is a glitch in code causing it to make way too many at once. Hence, call me.
                    {
                        string Jesus = "Contact me (Josh Simpson), error handling needs looking at in static void monitor directory";
                        File.WriteAllText(Aidpath, Jesus);
                    }
                    Console.WriteLine(Spacer);
                    //If everything goes wrong it will create errors then to allow it to continue running and not crash it has to monitor somewhere
                    //I'm making it monitor this path as its the most common one I've seen so far.
                    path = @"C:\LuK\Master\Zeichnungsdaten\L-01026-0G20-04";
                    JobName = "L-01026-0G20-04";
                    fileSystemWatcher.Path = path;
                }

            }
            catch (SystemException ex)
            {
                while (retryName < 5000)
                {
                    if (!File.Exists(errorpath))
                    {
                        PathError = PathError + ex;
                        File.WriteAllText(errorpath, PathError);
                        Console.WriteLine(PathError);
                        retryName = 0;
                        NewNameCount = 0;

                        break;
                    }
                    else if (errorpath.Length <= 250)
                    {
                        string ErrorPathName = ErrorPathNameMaster;
                        NewNameCount++;
                        retryName++;
                        ErrorPathName = ErrorPathNameMaster + Convert.ToString(NewNameCount);
                        Console.WriteLine("ErrorFile Name exits. Attempting new file name -" + ErrorPathName);
                        errorpath = @"D:\JobEditsSaved\" + ErrorPathName + ".txt";
                    }
                    else if (errorpath.Length > 250)
                    {
                        NewNameCount = 0;
                        retryName++;
                        NewNameCount++;
                        Unlikely = "JobNameError,ClearSomeErrorsOut" + Convert.ToString(NewNameCount);
                        errorpath = @"D:\JobEditsSaved\" + Unlikely + ".txt";
                        Console.WriteLine("Errors need clearing - Still making logs fine though");
                    }
                    else
                    {
                        Console.WriteLine("What manner of thing hath gone wrong, I don't actually expect any of these statements to ever be called.\r\n Is there a new job thats not been added? Or format of dnoconfig??");
                        string Jesus = "Contact me (Josh Simpson), error handling needs looking at in static void monitor directory";
                        File.WriteAllText(Aidpath, Jesus);
                    }

                }
                Console.WriteLine(Spacer);
                //If everything goes wrong it will create errors then to allow it to continue running and not crash it has to monitor somewhere
                //I'm making it monitor this path as its the most common one I've seen so far.
                path = @"C:\LuK\Master\Zeichnungsdaten\L-01026-0G20-04";
                JobName = "L-01026-0G20-04";
                fileSystemWatcher.Path = path;

            }


            //Allows monitoring of subdirectories. - Not needed as shouldn't be any:
            fileSystemWatcher.IncludeSubdirectories = true;

            //Declaring the filters, I don't really know why its needed for the monitoring of changes, creation, deletion ECT but it is.
            fileSystemWatcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                | NotifyFilters.FileName | NotifyFilters.DirectoryName;

            //Calling the SystemWatcherFunctions
            fileSystemWatcher.Changed += FileSystemWatcher_Changed;
            fileSystemWatcher.Error += new ErrorEventHandler(OnError);


            Console.WriteLine("This is monitoring {0}{1}", path, Spacer);
            //enables the monitoring
            fileSystemWatcher.EnableRaisingEvents = true;


        }
        public static void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            //This is for the sizes and file info. We are grabbing the resutls but also creating a converted version so I can't display in MB for large file with accuracy
            /*var info = new FileInfo(e.FullPath);
            var size = Convert.ToInt64(0);

            //declaring to be used, double allows decimals. 64bitInt does not.
            double MBSIZE = 0;
            //This is to avoid potential error. Ensures the info we are grabbing is in the direct directory and no sub ones.
            if ((info.Attributes & FileAttributes.Directory) != FileAttributes.Directory)
            {
                size = info.Length;
            }
            //This is for making it into megabytes for unnecessary user friendliness
            if (size > 2000)
            {
                MBSIZE = Convert.ToDouble(size);
                MBSIZE = MBSIZE / 1000000;

                Console.WriteLine("File Changed/Edited/saved: {0}\r\nwas modified on {1}\r\nit is {2} Megabytes in size\r\nIs was originally created on {3}", e.Name, modification, MBSIZE, creation, Spacer);
            }
            else
            *///{
                Console.WriteLine("File Changed/Edited/saved: {0}\r\nwas modified on {1}\r\nIs was originally created on {2}{3} ", e.Name, modification, creation, Spacer);
            //}


            //The changed Files Name, then its location, then the date it was edited, then we take that date and convert to integer string, then remove all / as not to mess with directories.
            FileNameStore = e.Name;
            FilesPath = e.FullPath;
            DateTime FilesLastWrite = File.GetLastAccessTime(FilesPath);
            string FilesLastDone = FilesLastWrite.ToString("dd/MM/yyyy-HH:mm:ss");
            FilesLastDone = FilesLastDone.Replace("/", "-").Replace(":", ".");

            //This will be the files name when saved, this is  a combo of when It was edited and its original name
            string NewFileName = FilesLastDone + "_" + JobName + "_" + FileNameStore;
            string BackupLocation = @"D:\JobEditsSaved\";
            PasteLocation = BackupLocation + NewFileName;
            //ConsoleWrites to check everything passing what it should be
            Console.WriteLine("\r\n   --  NewFileName:{0}\r\n   --  FilesPath:{1}\r\n   --  FileNameStore:{2}\r\n   --  FilesLastDone:{3}\r\n   --  PasteLocation:{4}", NewFileName, FilesPath, FileNameStore, FilesLastDone, PasteLocation);

            if (CanRunTime)
            {
                CanRunTime = false;
                t.Interval = 2000;
                t.Elapsed += new ElapsedEventHandler(t_Elapsed);
                t.Start();
            }


        }```
0

There are 0 answers