Bug 26168 - AggregateException gets suppressed in AsParallel while enumerating
Summary: AggregateException gets suppressed in AsParallel while enumerating
Status: RESOLVED NORESPONSE
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 3.12.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-01-19 12:43 UTC by Stepan
Modified: 2017-09-04 22:30 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description Stepan 2015-01-19 12:43:21 UTC
Assume we have the following code:

class Program
{
    private static IEnumerable<int> Func()
    {
        yield return 1;
        yield return 2;
        throw new NullReferenceException();
    }

    public static void Main(string[] args)
    {
        try
        {
            foreach (var item in func1().AsParallel())
            {  
            }
            var result = func().AsParallel().ToList();
            Console.WriteLine("Nothing happened");
        }
        catch (AggregateException ex)
        {
            Console.WriteLine("Catch");
        }
        Console.WriteLine("Quiting");
    }
}

Expected output:
Catch
Quiting

Actual output on Windows (.net-framework 4.5.1)
Catch
Quiting

Actual output on Windows (.net-framework 4.5.1)
Nothing happened
Quiting

On Windows everything runs as expected - basically we throw an exception from Task, receive AggregateException.
But if we run the same code under Linux on mono we will see that the exception is suppressed and it just terminates looping over IEnumerable.

But if we modify the code above like this(introduce ToList() instead of foreach:

        try
        {
            var result = func().AsParallel().ToList();
            Console.WriteLine("Nothing happened");
        }
        catch (AggregateException ex)
        {
            Console.WriteLine("Catch");
        }
        Console.WriteLine("Quiting");

than the exception is fairly thrown and caught on both Windows and Linux(mono).
Comment 1 Stepan 2015-01-19 12:46:01 UTC
The second Actual output should be for Linux(mono)
Like this:

Actual output on Windows (.net-framework 4.5.1)
Catch
Quiting

Actual output on Linux(mono)
Nothing happened
Quiting
Comment 2 Marek Safar 2015-01-19 14:11:29 UTC
Please attach complete test case
Comment 3 Marek Safar 2017-09-04 22:30:21 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and reopen the bug report.

Thank you!