Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin反射破裂_C#_Xamarin_Reflection - Fatal编程技术网

C# Xamarin反射破裂

C# Xamarin反射破裂,c#,xamarin,reflection,C#,Xamarin,Reflection,当我想加载命名空间中的所有类时,我遇到了一个问题。因为我更新到MonoFramework>4.8,所以我的代码不再有效,但在早期版本中是有效的 public class ClassReflection : IClassReflection { public Type[] GetTypes(string ns) { Assembly asm = Assembly.GetExecutingAssembly(); List<string>

当我想加载命名空间中的所有类时,我遇到了一个问题。因为我更新到MonoFramework>4.8,所以我的代码不再有效,但在早期版本中是有效的

public class ClassReflection : IClassReflection
{
    public Type[] GetTypes(string ns)
    {
        Assembly asm = Assembly.GetExecutingAssembly();

        List<string> namespacelist = new List<string>();
        List<string> classlist = new List<string>();

        foreach (Type type in asm.GetTypes())
        {
            if (type.Namespace == ns)
                namespacelist.Add(type.Name);
        }

        return asm.GetTypes();
    }

    public Type[] GetTypes(AssemblyName name, string ns)
    {
        Assembly asm = Assembly.Load(name);

        List<string> namespacelist = new List<string>();
        List<string> classlist = new List<string>();

        var tps = asm.GetTypes();

        var types = asm.GetTypes().Where(t => t != null).Where(t => t.Namespace.StartsWith(ns));

        if (types == null)
        {
            Debug.WriteLine("Types is null");
            return null;
        }

        var arr = types.ToArray();
        return arr;
        //return types.Where(i => i != null).ToArray();
    }

    public bool IsSameOrSubclass(Type potentialBase, Type potentialDescendant)
    {
        return potentialDescendant.IsSubclassOf(potentialBase)
               || potentialDescendant == potentialBase;
    }
}
是否有人知道这是一个Bug,或者代码需要定制一点


谢谢你的帮助

您有一个类型,其中
t.Namespace
null
(这是合法的)。对
types.ToArray()
的调用在计算第二个
时失败,其中
。不,不存在t。命名空间==null。我查看了IEnumerable,没有找到任何可为null的值,然后要么JIT编译器坏了,要么这段代码不是实际执行的代码。包括完整堆栈跟踪。您有一个类型,其中
t.Namespace
null
(这是合法的)。对
types.ToArray()
的调用在计算第二个
时失败,其中
。不,不存在t。命名空间==null。我查看了IEnumerable,没有找到任何可为null的值,然后要么JIT编译器坏了,要么这段代码不是实际执行的代码。包括完整的堆栈跟踪。
var arr = types.ToArray();