Instance.GetType ().GetInterface (SomeInterfaceFullName, true) returns null only on MacOs

MatteoNicolotti.3744MatteoNicolotti.3744 ITMember ✭✭
edited January 2016 in Xamarin.iOS

This caused many troubles on an app that i had perfectly working about one year ago. The last parameter should control the "case invariance" of the search, but it seems not to be working as intended (the search fails with CaseInvariantSearch = true but it doesn't fail in more strict conditions.

Here is a test to demonstrate the issue.

using System;
using System.Reflection;

    interface InterfaceToBeImplemented  
    {
        int Sum(int a,int b); 
    }
    class InterfaceImplementingClass : InterfaceToBeImplemented 
    { 
        public int Sum (int a,int b) 
        { 
            return a + b; 
        } 
    }
    class MainClass
    {
        public static void Main (string[] args)
        {
            var instance = new InterfaceImplementingClass ();

            var interfaceImplementation1a = instance.GetType ().GetInterface (typeof(InterfaceToBeImplemented).FullName);
            Console.WriteLine( "Interface call 1a == null ? " + (interfaceImplementation1a == null));
            var interfaceImplementation1b = instance.GetType ().GetInterface (typeof(InterfaceToBeImplemented).FullName.ToLower());
            Console.WriteLine( "Interface call 1b == null ? " + (interfaceImplementation1b == null));

            var interfaceImplementation2a = instance.GetType ().GetInterface (typeof(InterfaceToBeImplemented).FullName, false);
            Console.WriteLine( "Interface call 2a == null ? " + (interfaceImplementation2a == null));
            var interfaceImplementation2b = instance.GetType ().GetInterface (typeof(InterfaceToBeImplemented).FullName.ToLower(), false);
            Console.WriteLine( "Interface call 2b == null ? " + (interfaceImplementation2b == null));

            var interfaceImplementation3a = instance.GetType ().GetInterface (typeof(InterfaceToBeImplemented).FullName, true);
            Console.WriteLine( "Interface call 3a == null ? " + (interfaceImplementation3a == null));
            var interfaceImplementation3b = instance.GetType ().GetInterface (typeof(InterfaceToBeImplemented).FullName.ToLower(), true);
            Console.WriteLine( "Interface call 3b == null ? " + (interfaceImplementation3b == null));

            Console.ReadKey ();
        }
    }

which returns :
Interface call 1a == null ? False
Interface call 1b == null ? True
Interface call 2a == null ? False
Interface call 2b == null ? True
Interface call 3a == null ? True
Interface call 3b == null ? True

Posts

Sign In or Register to comment.