6

I am getting the error whenever i try to debug my code and i am not able to proceed.

AsyncMethodBuilder.cs Not Found

Background Info:

I have to compress a huge volume of docs and with minimal time effort. I have a compression library and i am able to do the compression synchronously. But to speed up things i would like to compress docs in parallel (no of docs compressing at a time is programmable) such that 1. I would utilize the CPU properly and get the work done in optimal time.

To achieve the above I followed the this link to create multiple tasks and wait on them to complete

Below is the code I have tried.

public static class CompressAllTechniques
    {
        public static void Main()
        {
            GoCallAPIAsync();
        }

        private static async void GoCallAPIAsync()
        {
            try
            {
                List<Task> TaskList = new List<Task>();
// For Sample testing I have taken 4 files and will iterate through them to check the timings
                const string originalFile1 = @"Sample Data\source";
                const string originalFile2 = @"Sample Data\source1";
                const string originalFile3 = @"Sample Data\Original";
                const string originalFile4 = @"Sample Data\Original1";
                List<string> arr = new List<string>() { originalFile1, originalFile2, originalFile3, originalFile4 };
                int noofThreads = 2;       // No of tasks that has to run paralally
                int IterationsCompleted = 0;
                int TotalIterations = 10;
                var temp = arr;
                Console.WriteLine("\n\nProcess Started @ " + DateTime.Now);
                for (int i = 0; i < TotalIterations; i++)
                {
                    if (temp.Count == 0) temp = arr;
                    var sd = temp.Take(noofThreads);

                    foreach (var item in sd)
                    {
                        var LastTask = new Task(() => GoCompress(item, IterationsCompleted));
                        LastTask.Start();
                        TaskList.Add(LastTask);
                    }
                    temp = temp.Except(sd).ToList();

                    await Task.WhenAll(TaskList.ToArray());
                    TaskList.Clear();
                }
                Console.WriteLine("\n\nProcess Completed @ " + DateTime.Now);
                Console.Read();
            }
            catch (Exception ex)
            {
                throw;
            }

        }

        private static void GoCompress(string zdf, int dcnk)
        {
              // Compression Logic
        }        
    }

When I try to debug the above code I got the following Exception in Visual Studio.

Locating source for 'f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\AsyncMethodBuilder.cs'. (No checksum.)
The file 'f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\AsyncMethodBuilder.cs' does not exist.
Looking in script documents for 'f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\AsyncMethodBuilder.cs'...
Looking in the projects for 'f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\AsyncMethodBuilder.cs'.
The file was not found in a project.
Agnel Amodia
  • 765
  • 8
  • 18
Sashi
  • 63
  • 1
  • 5
  • 1
    Have you unchecked “Just my code” in the debugger settings? – stuartd Oct 11 '19 at 23:26
  • Thanks @stuartd, now i am able to debug the same. Can you suggest any better way to achieve the above one – Sashi Oct 11 '19 at 23:33
  • What .NET Framework are you targeting? – Paulo Morgado Oct 11 '19 at 23:39
  • Hi @stuartd, Now the code is not throwing any exceptions like before but the process is coming out of Debugging at `await Task.WhenAll(TaskList.ToArray());` line. And it is not Executing the `GoCompress` method. – Sashi Oct 11 '19 at 23:40
  • @PauloMorgado, I am targetting .Net 4.5 – Sashi Oct 11 '19 at 23:40
  • Your Main method signature is not `async Task` and you are not awaiting `GoCallAPIAsync` - The compiler would have warned you about this... – stuartd Oct 12 '19 at 00:18
  • And don’t use `async void` - always return a `Task`, i.e. `private static async Task GoCallAPIAsync()` – stuartd Oct 12 '19 at 00:21
  • @stuartd That is why, i am calling `GoCallAPIAsync` method in `main` and not awaiting for the same. but my compiler didnt give any warnings – Sashi Oct 12 '19 at 00:22
  • You should certainly have had a warning that an `async` method was not awaited. – stuartd Oct 12 '19 at 00:23
  • Ah wait, I think it might be because you’re not returning a task - or you would see _Because this call is not awaited, **execution of the current method continues before the call is completed**. Consider applying the 'await' operator to the result of the call._ – stuartd Oct 12 '19 at 00:25
  • Which is why you never see it hitting `GoCompress` – stuartd Oct 12 '19 at 00:27
  • @stuartd, I am `await`ing on array of tasks right.what should i do now...? – Sashi Oct 12 '19 at 00:29
  • What version of Visual Studio? – Paulo Morgado Oct 12 '19 at 12:01

1 Answers1

6

Like @stuartd said in the comments above, enable (check the box) for the debugging option "Enable Just My Code":

enable the debugging option Enable Just My Code

I got here from Google and although it doesn't seem like this helped @Sashi, it solved this error on my machine.

DanM7
  • 2,203
  • 3
  • 28
  • 46