Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, This is my code:
C#
        private void form_Load(object sender, EventArgs e)
        {
 string s = Directory.GetCurrentDirectory()+@"\plugin";
            Assembly assembly = Assembly.LoadFrom(s);
            AssemblyName assemblyn = assembly.GetName();
            MessageBox.Show(assemblyn.ToString());
}

When i trace my program the code in line 2 onwards will not run!!
I change it repeatedly but the code that related to Assembly class will not run and does not allow to subsequent code run also!

From comment: I want load my dll files from directory without use these names, in other hand i dont know the name of dll files.
Posted
Updated 7-May-15 7:08am
v2

1 solution

You need to provide the full path and file name to Assembly.LoadFrom(..)[^], e.g.:
C#
Assembly assembly = Assembly.LoadFrom(@"c:\test\MyAssembly.dll");

But you only provided a path (or, if "plugin" is the name of the file, you have to append ".dll" or, unlikely but possible, ".exe").

Edit after comment:

To load all assemblies from a specific directory, you can use Directory.EnumerateFiles(..)[^] to retrieve all (matching) files from the directory and then loop over the IEnumerable<string>-result to load them one by one. (The linked page has a sample code.)
 
Share this answer
 
v3
Comments
meliti 7-May-15 13:01pm    
Thanks for your solution. I want load my dll files from directory without use these names, in other hand i dont know the name of dll files.
Sascha Lefèvre 7-May-15 13:15pm    
Thank you for accepting my solution! I extended it, please take another look. I think that should cover you :)
Sergey Alexandrovich Kryukov 7-May-15 13:11pm    
5ed.
—SA
Sascha Lefèvre 7-May-15 13:15pm    
Thank you, Sergey.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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