0

I have a class in my Xamarin PCL which makes a call to System.Reflection.GetRuntimeProperties. For an example, let's say my PCL class has this method:

public string ExampleMethod(string arg) {
    if(arg == null) return null;
    IEnumerable<PropertyInfo> infos = this.GetType().GetRuntimeProperties();
    return infos[0].Name;
}

I then have a Xamarin.UITest project which references the PCL project and tests this class. I have two test cases in my TestFixture so far, which for our example would be the following:

    [Test]
    public void TestExampleMethod_ArgNull_Null(){
        Assert.That (exampleInstance.ExampleMethod(null), Is.Null);
    } 

    [Test]
    public void TestExampleMethod_ArgNotNull_NotNull(){
        Assert.That (exampleInstance.ExampleMethod("testValue"), Is.NotNull);
    } 

When I run the Xamarin.UITest project, it compiles, runs the tests, and completes fine on both Android and iOS platforms. The TestExampleMethod_ArgNull_Null test passes since it returns early. However, the TestExampleMethod_ArgNotNull_NotNull test fails with:

System.MissingMethodException : Method 'RuntimeReflectionExtensions.GetRuntimeProperties' not found.

So it appears that even though everything is compiling just fine, and I am able to run other test cases fine, the Xamarin.UITest project is not able to use anything in System.Reflection. Does anyone know how I go about debugging this?

thedigitalsean
  • 269
  • 1
  • 3
  • 10

2 Answers2

0

On my end, using the following failed to build:

IEnumerable<PropertyInfo> infos = this.GetType().GetRuntimeProperties();
return infos[0].Name;

due to not being able to do bracket indexes on and IEnumerable. I changed to this:

List<PropertyInfo> infos = this.GetType().GetRuntimeProperties().ToList();
return infos[0].Name;

And the project built and the tests ran successfully.

The class with the method using Reflection was in a PCL which was referenced from a UI Test project.

So basically I am not able to reproduce the error you got.

jgoldberger - MSFT
  • 5,978
  • 2
  • 20
  • 44
  • I think OP is referring to this extension method: https://msdn.microsoft.com/en-us/library/system.reflection.runtimereflectionextensions.getruntimeproperties%28v=vs.110%29.aspx – thumbmunkeys Jul 28 '15 at 11:15
0

I posted this to Xamarin Support as well (thanks @jgoldberger) and we were able to figure out that it was due to a project setup issue. This is a project which uses Couchbase Lite which requires a specific version of Json.Net (6.0.4 as of this post). I must have accidentally updated the packages on some of the projects since the same version of Json.Net was not being used across all the projects (PCL, Android, iOS, and UITest). I ended up re-creating the project from scratch and that took care of it.

thedigitalsean
  • 269
  • 1
  • 3
  • 10