mercredi 30 décembre 2020

MethodInfo.GetParameters() throws System.IO.FileNotFound Exception

I am developing a project where I gather information from a previously created DLL file. I basically get structure of the DLL.

I use the following code to gather information.

public void Decode(string[] additionalFiles)
{
    Assembly assembly = Assembly.LoadFile(this.dllLocation);
    if(additionalFiles != null && additionalFiles.Length > 0)
        foreach (string af in additionalFiles)
        {
            Assembly additionalAssembly = Assembly.LoadFrom(af);
            AppDomain.CurrentDomain.Load(additionalAssembly.GetName());
        }
    Type[] types = assembly.GetTypes();
    Type[] public_classes = types.Where(x => x.IsPublic && !x.IsInterface).ToArray();
    foreach (Type type in public_classes)
    {
        if(type.IsClass)
        {
            MethodInfo[] class_methods = type.GetMethods().Where(x => x.Module.ScopeName != "CommonLanguageRuntimeLibrary").ToArray();
            for (int i = 0; i < class_methods.Length; i++)
            {
                try
                {
                    MethodInfo mi = class_methods[i];
                    ParameterInfo[] pars = mi.GetParameters();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
    }
}

I get the assembly, classes, and methods. But when I try to get the parameters of a method I get System.IO.FileNotFound Exception. The code stops and opens OpenFileDialog. If I choose the same dialog again code restarts and gives the same Exception at the same point.

If I stop the code and try to see the properties of MethodInfo mi, I see the Exception is thrown.

Where I am doing wrong and what is the proper solution. I Googled it but it seems that I am playing by the book.

The Exception information I see is shown in the image enter image description here





Aucun commentaire:

Enregistrer un commentaire