Search code examples
androidxamarinxamarin.formssystem.reflection

xamarin forms android runtime reflection GetMethods always zero?


I have a problem to GetMethods for an interface in xamarin forms android. When I getting list of methods of an interface I always get nothing. This problem is when I call GetMethods of Type when that Type is in another project (not in android project) and if that type is inside of android project I dont have any problems to get Methods of interface. For Example:

    [ServiceContract("AuthenticationService", InstanceType.SingleInstance)]
    public interface IAuthentication
    {
        MessageContract<(int Id, Guid password)> RegisterUser(UserInfo userInfo);
        MessageContract<int> Login(string userName, string password);
        MessageContract<Guid> ConfirmUserWithSMS(int userId, int randomNumber);
    }

var type = typeof(IAuthentication);
var methods = type.GetMethods();//return zero
var m = type.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);//return zero
var methods2 = type.GetTypeInfo().GetMethods();//return zero
var m2 = type.GetTypeInfo().GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);//return zero
var methods3 = type.GetTypeInfo().DeclaredMethods.ToList();//return zero

Solution

  • After a few hours When I changed setting of Linking in Android Options to "None" the problem gone: enter image description here