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);
            }
        }
    }
}
9
  • 2
    What version of Visual Studio are you using? Commented Nov 24, 2020 at 9:15
  • Where is line 30? Commented Nov 24, 2020 at 9:17
  • Which line in the code you've posted corresponds to line 30 in the error messages? Commented Nov 24, 2020 at 9: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 Commented Nov 24, 2020 at 9: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); Commented Nov 24, 2020 at 9:22

1 Answer 1

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);
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.