1

When attempting to download asset files for Minecraft, half of the files fail with a download error : "An exception occurred during a WebClient request."

With the InnerException being : "{"The process cannot access the file 'C:\\Users\\[redacted]\\AppData\\Roaming\\[redacted]\\Minecraft 1.10\\assets\\objects\\bdbdf48ef6b5d0d23bbb02e17d04865216179f510a' because it is being used by another process."}".

I am using the FileDownloadCompleted event.

I have also tried adding a "." to the end of each file that doesn't have a proper extension but it has not solved the problem.

Also, this problem is not consistent. Some files with similar names download normally, while other files fail to download. However, it's not an Internet issue either and I have tested on multiple computers.

How can I resolve this exception?

Malcolm Salvador
  • 1,476
  • 2
  • 21
  • 40
Unknown025
  • 21
  • 5
  • Hi, could it be whitespace maybe in the filename(s)? You could try removing it if so. i.e `someString.Replace(" ", string.Empty);` – Craig Mayers May 23 '17 at 23:25
  • 1
    That message is common for "some other program has a lock on it". – JWP May 23 '17 at 23:27
  • @John Peters, I understand what the error means, but this is a file that's being downloaded from scratch, no other programs even know about this file. – Unknown025 May 24 '17 at 03:51
  • @Craig Mayers Most of the filepaths (including the example) do not have any spaces at all, including the filename. – Unknown025 May 24 '17 at 03:52
  • When this happens with the normal launcher, this is caused by an antivirus (usually ByteFence). Probably the same thing here. – Pokechu22 May 24 '17 at 14:59
  • @Pokechu22 well, I just have Microsoft Security Essentials installed (on Windows 7), and Security Essentials didn't flag anything, and the normal Minecraft launcher works perfectly fine. – Unknown025 May 24 '17 at 19:39

1 Answers1

1

As a makeshift workaround, I have added a while loop to wait for the file to become available.

else if(e.Error.InnerException is IOException)
                    {
                        bool canAccess = false;
                        while (!canAccess)
                        {
                            try
                            {
                                File.Move(Userstate[0], Userstate[0]);
                                canAccess = true;
                                Debug.Print("Can now access file: " + Userstate[0]);
                            }
                            catch(IOException) { }
                        }
                    }

This code is part of the DownloadCallback handler, and checks the status of e.Error.InnerException. This does not seem like the best solution, but it's the only one I have come up with.

Unknown025
  • 21
  • 5