0

I'm not sure why I am getting this error.I am trying to build this on Visual Studio.I am new but i need to build this code.

There are my errors and code :

(30,19): error CS1003: Syntax error, '(' expected

(30,88): error CS1026: ) expected

(31,19): error CS1003: Syntax error, '(' expected

(31,51): error CS1026: ) expected

(36,23): error CS1003: Syntax error, '(' expected

(36,63): error CS1026: ) expected

(37,23): error CS1003: Syntax error, '(' expected

(37,156): error CS1026: ) expected

namespace MelonLoader.AssemblyGenerator
{
    public static class DownloaderAndUnpacker
    {
        public static void Run(string url, string targetVersion, string currentVersion, string destinationFolder, string tempFile)
        {
            if (targetVersion == currentVersion)
            {
                Logger.Log($"{destinationFolder} already contains required version, skipping download");
                return;
            }
            
            Logger.Log($"Cleaning {destinationFolder}");
            foreach (var entry in Directory.EnumerateFileSystemEntries(destinationFolder))
            {
                if (Directory.Exists(entry))
                    Directory.Delete(entry, true);
                else
                    File.Delete(entry);
            }

            Logger.Log($"Downloading {url} to {tempFile}");
            Program.webClient.DownloadFile(url, tempFile);
            Logger.Log($"Extracting {tempFile} to {destinationFolder}");
            
/*line 30*/ using var stream = new FileStream(tempFile, FileMode.Open, FileAccess.Read);
            using var zip = new ZipArchive(stream);
            
            foreach (var zipArchiveEntry in zip.Entries)
            {
                Logger.Log($"Extracting {zipArchiveEntry.FullName}");
                using var entryStream = zipArchiveEntry.Open();
                using var targetStream = new FileStream(Path.Combine(destinationFolder, zipArchiveEntry.FullName), FileMode.OpenOrCreate, FileAccess.Write);
                entryStream.CopyTo(targetStream);
            }
        }
    }
}
Cid
  • 14,968
  • 4
  • 30
  • 45
EmiRZ
  • 11
  • 2
    What version of Visual Studio are you using? – Steve Nov 24 '20 at 09:15
  • Where is line 30? – Cid Nov 24 '20 at 09:17
  • Which line in the code you've posted corresponds to line 30 in the error messages? – canton7 Nov 24 '20 at 09:17
  • 3
    I suppose that you are not using C# 8.0. And the syntax used for the using statements requires C# 8.0. Thus my question about the Visual Studio version. Probably you need to enable C# 8.0 or later – Steve Nov 24 '20 at 09:20
  • line 30 : using var stream = new FileStream(tempFile, FileMode.Open, FileAccess.Read); line 31 : using var zip = new ZipArchive(stream); line 36: using var entryStream = zipArchiveEntry.Open(); line 37 : using var targetStream = new FileStream(Path.Combine(destinationFolder, zipArchiveEntry.FullName), FileMode.OpenOrCreate, FileAccess.Write); – EmiRZ Nov 24 '20 at 09:22
  • Yep, Steve was right. You'll need to use a more recent version of Visual Studio (just grab the latest), or convert the newer C# syntax to the older equivalent – canton7 Nov 24 '20 at 09:24
  • I am using visual studio 2017 @Steve – EmiRZ Nov 24 '20 at 09:24
  • Thanks @canton7 and Steve . I am updating to lastest version now. – EmiRZ Nov 24 '20 at 09:26
  • And apart from Mr Gravell answer below there is also the possibility explained here https://stackoverflow.com/questions/54701377/how-can-i-use-c-sharp-8-with-visual-studio-2017 but compared to that solution I really suggest to join the latest release of VS – Steve Nov 24 '20 at 09:29

1 Answers1

2

This seems to be C# 8 "using declarations"; it is possible that you have an up to date compiler available, but your csproj is configured to use down-level C#; it is possible that editing the cspoj to update or add:

<LangVersion>8</LangVersion>

(or higher, inside a <PropertyGroup> element)

would fix it.

If you can't use C# 8, then:

using (var stream = new FileStream(tempFile, FileMode.Open, FileAccess.Read))
using (var zip = new ZipArchive(stream))
{

    foreach (var zipArchiveEntry in zip.Entries)
    {
        Logger.Log($"Extracting {zipArchiveEntry.FullName}");
        using (var entryStream = zipArchiveEntry.Open())
        using (var targetStream = new FileStream(Path.Combine(destinationFolder, zipArchiveEntry.FullName), FileMode.OpenOrCreate, FileAccess.Write))
        {
            entryStream.CopyTo(targetStream);
        }
    }
}
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900