Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have this function:
C#
public void LoadPlugins()
        {
            foreach (FileInfo f in new DirectoryInfo(pDir).GetFiles())
            {
				if (f.Extension.ToLower() != ".dll")
					continue;
                try {
                    string path = f.FullName;
                    Assembly DLL = Assembly.LoadFile(path);
                    foreach (Type t in DLL.GetExportedTypes())
                    {
                        if (t.Equals(typeof(IPlugin)))
                        {
                            IPlugin plugin = (IPlugin)Activator.CreateInstance(t);
                            plugin.Initialize(prgm, players);
                            if (Plugins.ContainsKey(plugin.PluginName))
                            {
                                prgm.LogMessage("Duplicate plugin name detected: \"" + plugin.PluginName + "\"", LogLevel.Error);
                                continue;
                            }
                            Plugins.Add(plugin.PluginName, plugin);
                        }
                    }
                }
                catch (Exception e)
                {
                    prgm.LogMessage(e.Message, LogLevel.Error);
                }
            }
        }


It should load DLL's from the plugins folder into a dictionary of plugins, but the line:
C#
Assembly DLL = Assembly.LoadFile(path);

keeps returning a BadImageFormatException. I have checked and the .net framework version is the same in both the dll and the loader, and they are both built for x86 architecture, I have tried rebuilding it just in case the one build had become corrupt, I have no idea why I continue to receive an error.

Call Stack:
>	CorpHack.exe!CorpHack.Plugin.PluginLoader.LoadPlugins() Line 56	C#
 	CorpHack.exe!CorpHack.Plugin.PluginLoader.NewLoadPlugins(string dir, CorpHack.AdminWindow program) Line 76	C#
 	CorpHack.exe!CorpHack.AdminWindow.Form1_Load(object sender, System.EventArgs e) Line 102	C#
 	[External Code]	
 	CorpHack.exe!CorpHack.Program.Main(string[] args) Line 20	C#
 	[External Code]	


The message from the exception:
Could not load file or assembly 'BasePlugin.dll' or one of its dependencies.  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)


More exception details: http://hastebin.com/pokuvuvere.tex[^]

Regards,
Jordan
Posted
Updated 29-Nov-14 22:37pm
v4
Comments
DamithSL 30-Nov-14 4:28am    
what is the full error with stacktrace?
Sicppy 30-Nov-14 4:33am    
Edited question to include the call stack and exception message.
Kornfeld Eliyahu Peter 30-Nov-14 4:42am    
You may have a 32/64 bit problem...
Sicppy 30-Nov-14 4:43am    
Well both of them are being built with the x86 architecture
Kornfeld Eliyahu Peter 30-Nov-14 4:50am    
Check the causes in this page: http://msdn.microsoft.com/en-us/library/system.badimageformatexception%28v=vs.110%29.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900