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)

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 for Bug 37772 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

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.