Bug 634 - cannot compile using IEnumerable<my interface>
Summary: cannot compile using IEnumerable<my interface>
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 4.x
Hardware: Macintosh Mac OS
: --- major
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-09-05 01:52 UTC by Tohru Ohta
Modified: 2011-09-21 08:32 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 Developer Community or GitHub 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 INVALID

Description Tohru Ohta 2011-09-05 01:52:20 UTC
I tried to compile following sample code, but compiler error.
I'm using Mono 2.10.5.

using System;
using System.Collections.Generic;

namespace Test
{
	public class TestClass : ITestClass
	{
		public TestClass ()
		{	
		}
	}
	
	public interface ITestClass
	{
	}
	
	public static class TestClass2
	{
		public static void Test()
		{
			List<TestClass> list = new List<TestClass>();
			list.Add(new TestClass());
			TestInterface(list);
		}
		public static void TestInterface(IEnumerable<ITestClass> arg) 
		{
		}
	}
}

Error CS1502: The best overloaded method match for `Test.TestClass2.TestInterface(System.Collections.Generic.IEnumerable<Test.ITestClass>)' has some invalid arguments (CS1502) (test)
Error CS1503: Argument `#1' cannot convert `System.Collections.Generic.List<Test.TestClass>' expression to type `System.Collections.Generic.IEnumerable<Test.ITestClass>' (CS1503) (test)
Comment 1 Marek Safar 2011-09-05 04:49:08 UTC
You need to use dmcs compiler (.NET 4.0 profile) which supports interface covariance
Comment 2 Tohru Ohta 2011-09-06 05:02:14 UTC
Thank you.

I'm using MonoDevelop 2.6RC2 and could compile properly by changing Runtime verion to MONO / .Net4.0 in case C# Library Project.

There is option in Project Options -> Build -> General -> Runtime version.

But When I choose MonoTouch Library Project, I can't change this option and always disabled.
I need to compile by MonoTouch Library.
Could you tell me how I use dmcs compiler in this case?
Comment 3 Rolf Bjarne Kvinge [MSFT] 2011-09-21 08:32:04 UTC
Unfortunately you can't choose the compiler for MonoTouch.

It will be updated in a future release, but this is still somewhat far ahead (in particular it will not be in the next 5.0 release).