Bug 37772 - Instance.GetType ().GetInterface (SomeInterfaceFullName, true) returns null only on MacOs
Summary: Instance.GetType ().GetInterface (SomeInterfaceFullName, true) returns null o...
Status: NEW
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-18 15:36 UTC by Chris Hamons
Modified: 2016-04-28 15:15 UTC (History)
4 users (show)

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


Attachments

Description Chris Hamons 2016-01-18 15:36:25 UTC
Note: I am filing this bug from a report from the XM forums on behalf of the user. I have not personally verified the behavior status.

Post - https://forums.xamarin.com/discussion/59287/instance-gettype-getinterface-someinterfacefullname-true-returns-null-only-on-macos
---------

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
Comment 1 Martin Vahi 2016-04-28 15:15:30 UTC
I do not know, if it is a duplicate or not, but
I accidentally submitted a my bug report to

https://github.com/dotnet/roslyn/issues/10865

I used openSUSE Linux, 64 bit, mono. Please feel free
to make it a new, separate, bug report, if You believe
that it deserves to be separate.

Thank You.

Note You need to log in before you can comment on or make changes to this bug.