Closed
Description
Steps to Reproduce
Test code:
interface I {
void Foo ();
void Bar ();
}
class A : I {
public void Foo () { }
public void Bar () { }
}
class B : I {
public void Foo () { }
public void Bar () { }
}
public class InterfaceTest {
static Type type_a = typeof (A);
static Type type_b = typeof (B);
static Type type_i = typeof (I);
static void F (I i)
{
i.Bar ();
}
public static void Bug10866 ()
{
var a = new A ();
a.Foo ();
a.Bar ();
F (new A ());
I [] Ifaces = (I []) (object) new B [0];
}
}
We also have a unit test for this: 93eb592
The problem is that the linker removed the I
interface from the B
class, when it's not safe to do so.
Ref: dotnet/linker#1459
Ref: dotnet/linker#1305
Expected Behavior
No exception
Actual Behavior
System.InvalidCastException: Specified cast is not valid.
at InterfaceTest.Bug10866 () [0x00020] in /Users/rolf/Projects/TestApp/test-app/AppDelegate.cs:78
at AppDelegate.Tapped () [0x00001] in /Users/rolf/Projects/TestApp/test-app/AppDelegate.cs:91
at AppDelegate.<FinishedLaunching>b__4_0 (Foundation.NSTimer v) [0x00000] in /Users/rolf/Projects/TestApp/test-app/AppDelegate.cs:100
at Foundation.NSTimerActionDispatcher.Fire (Foundation.NSTimer timer) [0x00000] in /Users/rolf/work/maccore/msbuild/xamarin-macios/src/Foundation/NSAction.cs:105
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/rolf/work/maccore/msbuild/xamarin-macios/src/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/rolf/work/maccore/msbuild/xamarin-macios/src/UIKit/UIApplication.cs:65
at AppDelegate.Main (System.String[] args) [0x00001] in /Users/rolf/Projects/TestApp/test-app/AppDelegate.cs:121
Environment
xamarin-macios: 9a746d6