I refer to this
Can I load a .NET assembly at runtime and instantiate a type knowing only the name?
trying to add shell32.dll as reference, here is the code
string assemblyName = "Interop.Shell32.dll";
string assemblyPath = HttpContext.Current.Server.MapPath(assemblyName);
Assembly assembly = Assembly.LoadFrom(assemblyPath);
Type T = assembly.GetType("ShellClass");
ShellClass instance = (ShellClass)Activator.CreateInstance(T);
ShellClass sh = new ShellClass();
The above code has errors:
The type or namespace name 'ShellClass' could not be found (are you missing a using directive or an assembly reference?)
Also have a trial
Assembly assembly = Assembly.LoadFrom("Interop.Shell32.dll");
Type type = assembly.GetType("ShellClass");
object ShellClass = Activator.CreateInstance(type);
Error:
The type or namespace name 'ShellClass' could not be found
I'm not really understand how to add reference programmatically. What is the problem of above code?