Bug 15186 - Runtime crash related to generic covariance starting in Xamarin.iOS 6.4.X
Summary: Runtime crash related to generic covariance starting in Xamarin.iOS 6.4.X
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: 3.2.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-10-03 16:45 UTC by Damon Bohls
Modified: 2013-11-05 03:39 UTC (History)
6 users (show)

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


Attachments
The project which crashes as discussed in the bug description. (5.07 MB, application/x-zip-compressed)
2013-10-03 16:48 UTC, Damon Bohls
Details


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 FIXED

Description Damon Bohls 2013-10-03 16:45:46 UTC
We have a large application which began crashing sometime after the Xamarin.iOS 6.2.7.1 release. I believe the crash was possibly introduced by Xamarin 6.4.0.2 or one of the next few versions, but I cannot tell for sure because I receive various build errors when I attempt to use those versions.

I whittled the crash down to the attached project. The attached project crashes when run with Xamarin.iOS 6.4.0.2 or later. Earlier versions produce a compiler error regarding incompatible types, even though the large project this code came from does not produce any compiler errors.

Essentially, we are passing an object of type IEnumerable<IDisposable> into a method that expects IEnumberable<object>. In the method, I can cast the parameter to an IEnumerable<IDisposable> and call methods on the casted object. However, using the 'is' operator returns false, which should then mean it cannot be cast. Also, calling IEnumberable methods on the uncast object results in a crash.
Comment 1 Damon Bohls 2013-10-03 16:48:34 UTC
Created attachment 5058 [details]
The project which crashes as discussed in the bug description.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2013-10-04 06:46:00 UTC
Zoltan, this looks like a codegen bug of some sorts.

Here is a crash report from my device: https://gist.github.com/rolfbjarne/2233798dbc847f229f77

In the simulator it doesn't crash, but it still prints this:

    Casting succeeded but the 'is' operator returned false.
Comment 5 Zoltan Varga 2013-11-01 09:46:50 UTC
-> runtime.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
using System;
using System.Linq;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using System.Threading;

    public sealed class DerivedClass : BaseClass<object>
    {
    }

    public class BaseClass<T>
    {
        public void BaseMethod(IEnumerable<T> param)
        {
            bool isEnumerableClass = (param is EnumerableClass);
            EnumerableClass enumerableClass = param as EnumerableClass;
            if (enumerableClass != null && !isEnumerableClass)
            {
                Console.WriteLine("Casting succeeded but the 'is' operator returned false.");
                Console.WriteLine("enumerableClass.Count: " + enumerableClass.Count());
                Console.WriteLine("param.Count: " + param.Count());
                Console.WriteLine("Crashes?");
            }
        }
    }

    public sealed class EnumerableClass : IEnumerable<IDisposable>
    {
        public IEnumerator<IDisposable> GetEnumerator()
        {
            IEnumerable<IDisposable> data = new IDisposable[1];
            return data.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }

public class Tests
{
	public static void Main (String[] args) {
            DerivedClass derivedClass = new DerivedClass();
            EnumerableClass enumerableClass = new EnumerableClass();
            derivedClass.BaseMethod(enumerableClass);
	}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Comment 6 Zoltan Varga 2013-11-01 11:33:50 UTC
The 'is' fails but 'as' succeeds issue was due to an mcs bug, which is fixed in master now.
Comment 7 Zoltan Varga 2013-11-04 13:49:30 UTC
I can't reproduce the crash with master/7.0.4. This might be a dup of:
https://bugzilla.xamarin.com/show_bug.cgi?id=15345
Comment 8 Rolf Bjarne Kvinge [MSFT] 2013-11-05 03:39:41 UTC
I can confirm the test case doesn't crash on device anymore.

The 'is' failing but 'as' succeeding will be fixed in a Mono update (it'll probably be included in 3.2.6).