I try to write the C# program with 2 files: SyncService.cs and Program.cs as followed:

Program.cs

using System;
using System.Diagnostics;

namespace AzcopySync
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Trace.Listeners.Add(new ConsoleTraceListener());
            Trace.WriteLine("Program Started - " + DateTime.Now.ToString());Trace.WriteLine("");

            //Call into a separate class or method for the actual program logic
            //DoSomething(); //I'll use Trace for output in here rather than Console
            string source = "/home/potivora/data";
            string dest = "https://dfqualifstoracc.blob.core.windows.net/media-shutima";
            SyncService mySyncService = new SyncService();
            //mySyncService.TriggerBlobSync(source, dest);

            Console.WriteLine(mySyncService.TriggerBlobSync(source, dest));
         
            Trace.WriteLine("");Trace.WriteLine("Program Finished - " + DateTime.Now.ToString());

            Console.Write("Press a key to exit...");
            Console.ReadKey(true);
            Console.WriteLine();
        }
    }
}

SyncService.cs

using System;
using System.Diagnostics;

namespace AzcopySync
{
   public class SyncService 
   {
      const string AZCOPY_SYNC_CMD = " sync \"{0}\" \"{1}{2}\" --recursive";
      const string SASToken = "?sv=2019-10-10&si=upload-images&sr=c&sig=WZ7b6EbuPNev1cGEmepuy4%2FTNKBgvZ5zqEU246KrSNs%3D";
   
      public SyncService ()
      {
      }

      public string TriggerBlobSync(string sourcePath, string destPath)
      {
         ProcessStartInfo si = new ProcessStartInfo("azcopy")
         {
             Arguments = string.Format(AZCOPY_SYNC_CMD, sourcePath, destPath, SASToken),
             CreateNoWindow = true,
             UseShellExecute = false,
             RedirectStandardOutput = true
         };

         Console.WriteLine(si.FileName + "" + si.Arguments);

         var process = Process.Start(si);
         return process.StandardOutput.ReadToEnd();
      }
   
   }
}

When I do "dotnet run", I get this error message.

compileERR

Normally my code already compile and run correctly just with SyncService.cs. However, I decided to add Program.cs since I saw many example of C# program on Internet with the file Program.cs in the project as well even though I am not sure if I need to have it or not. So I actually, move the main function from SynService.cs to Program.cs because I think I should have only 1 main as I got another error about this before fixing this issue. Could you please help me to point out what can be the root cause?

0

There are 0 best solutions below