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

  • Question

  • User1071 posted

    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

    Saturday, January 16, 2016 7:35 PM

All replies

  • User35201 posted

    This may be a mono bug. I have not dug into the specifics to verify, but your example looks clear enough.

    I filed a bug so the runtime team can take a look.

    https://bugzilla.xamarin.com/show_bug.cgi?id=37772

    Monday, January 18, 2016 3:38 PM