lundi 20 juin 2016

Unable to load one or more of the requested types c# Reflection

i've got a project where i search on another project bin directory on the purpose of write all the methods from each assembly:

public static List<ManagerMethodDescr> getManagerMethodDescr(string nomeClasse)
    {
        DirectoryInfo inf = new DirectoryInfo(@"C:\NETASUITE\Backend\NETASIAL\Business\Managers.Common\bin");
        FileInfo[] fileDll = inf.GetFiles("*.dll");

        List<ManagerMethodDescr> ManagerDesc = new List<ManagerMethodDescr>();

        foreach (FileInfo fi in fileDll)
        {
            Assembly newAss = Assembly.LoadFile(fi.FullName);
            try
            {
                foreach (Type tipo in newAss.GetTypes())
                {
                    if (tipo.Name == nomeClasse)
                    {
                        MethodInfo[] mis = tipo.GetMethods();
                        foreach (MethodInfo mi in mis)
                        {
                            IEnumerable<CustomAttributeData> ieC = mi.CustomAttributes;
                            string arg = "";
                            if (ieC.Count() > 0)
                            {
                                if (ieC.ElementAt(0).ConstructorArguments.Count > 0)
                                {
                                    arg = ieC.ElementAt(0).ConstructorArguments[0].ToString().Replace("\"", "");
                                }
                            }
                            if (mi.IsPublic && arg == "Interfaccia")
                            {
                                MethodAttributes ma = mi.Attributes;
                                string ritorno = mi.ReturnType.Name.ToString();
                                string name = mi.Name;
                                ParameterInfo[] pi = mi.GetParameters();
                                List<string[]> Param = new List<string[]>();
                                foreach (ParameterInfo ppi in pi)
                                {
                                    Param.Add(new string[] { ppi.Name, ppi.ParameterType.Name.ToString() });
                                }
                                ManagerDesc.Add(new ManagerMethodDescr(ritorno, name, Param, mi.ReturnType.Namespace));
                            }
                        }
                    }
                }
            }
            catch (ReflectionTypeLoadException e)
            {
             IEnumerable<Type> iet=   e.Types.Where(t => t != null);


            }

        }
        return ManagerDesc;
    }

for some assembly i get error like "Could not load type 'NETA.SUITE.SIAL.Tipi.Base.SialBaseType' from assembly 'NETA.SUITE.SIAL.Tipi.Base" even if the references are well written and all set to copy local true...i can't get rid of it...i tryied with a simple project i made for example purpose and it worked...





Aucun commentaire:

Enregistrer un commentaire