0
votes

I tried googling a lot but failed to found a solution.

Please help me through.

I have a windows application setup wizard which will run a installer class where custom actions are assigned to do.

The project lies with a plugin architecture.

While installing, i need to install a printer driver, installer class have code to install it, by calling that plugin.

But, when i try to retrieve the loaded plugin's GetTypes() property, i am receiving a loader-exception Error and Installer will Quit.

If i run my windows application, then GetTypes() property is working properly.

Here is my code. Please have a look and check if anything went wrong.

   private static List<Assembly> LoadPlugInAssemblies()
    {

        DirectoryInfo dInfo = new DirectoryInfo(Path.Combine(Assembly.GetExecutingAssembly().Location.Replace("PluginSDK.dll", ""), "Plugins")); 

        FileInfo[] files = dInfo.GetFiles("*.dll");

        List<Assembly> plugInAssemblyList = new List<Assembly>();

        if (null != files)
        {
            foreach (FileInfo file in files)
            {
                plugInAssemblyList.Add(Assembly.LoadFile(file.FullName));
            }
        }
        return plugInAssemblyList;
    }

    static List<IUserFunctionPlugin> GetPlugIns(List<Assembly> assemblies)
    {
        List<Type> availableTypes = new List<Type>();

        foreach (Assembly currentAssembly in assemblies)
            availableTypes.AddRange(currentAssembly.GetTypes());

        List<Type> pluginList = availableTypes.FindAll(delegate(Type t)
        {
            List<Type> interfaceTypes = new List<Type>(t.GetInterfaces());
            object[] arr = t.GetCustomAttributes(typeof(PluginAttributes), true);
            return !(arr == null || arr.Length == 0) && interfaceTypes.Contains(typeof(IUserFunctionPlugin));
        });

        // CONVERT THE LIST OF OBJECTS TO AN INSTANTIATED LIST OF IPlugins
        return pluginList.ConvertAll<IUserFunctionPlugin>(delegate(Type t) { return Activator.CreateInstance(t) as IUserFunctionPlugin; });
    }

I tried with Assembly.ReflectionOnlyLoad but resulted with the same error. Thanks in Advance!!!

1
You should catch the exception and log/show/output it so you can determine the cause. - logicnp
Ok @logicnp : this is the log i received. Could not load file or assembly 'PluginSDK, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. Fusion Log: WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. - csLijo

1 Answers

0
votes

If that is assembly bind error try running Fuslogvw.exe (Assembly Binding Log Viewer) to collect more information about the error.