I am writting a plugin for a program, and I want to put my code inside a DLL so I can share the plugin freely without exposing (giving away) my code.
Here is the bas
FYI, remember to use a tool like Red-Gate's .Net Reflector to inspect your DLL to make sure it is properly obfuscated. This free, visual tool lets you see the DLL as your users will see it so you'll know if your code is exposed
alt text http://img149.imageshack.us/img149/2025/screenshotfullscreen.gif
.Net comes with Dotfuscator Community Edition which can be used to obfuscate your code. No coding is required, see their user guide to learn your way around the GUI if you need help.
Use the static Assembly.Load() / Assembly.LoadFile() / Assembly.LoadFrom() methods to dynamically load assemblies.
Found exactly what I was looking for, here it is:
using System.Reflection;
using System.IO;
try
{
Assembly a = null;
a = Assembly.LoadFrom(Application.StartupPath startupPath + "MyAssembly.dll");
Type classType = a.GetType("MyNamespace.MyClass");
object obj = Activator.CreateInstance(classType);
MethodInfo mi = classType.GetMethod("MyMethod");
mi.Invoke(obj, null);
}
catch (Exception e)
{
AddLog(e.Message);
}
The best option would be to use a framework for creating extensible applications:
If you want to do it manually, you can use the Assembly.Load*() methods to load an assembly at runtime. You can search the assembly for types that implement a specific interface and then create instances using Activator.CreateInstance. The assemblies can be compiled separately, you just have to reference an assembly that contains the interface shared by application and plugin.
For obfuscation, there are a couple of obfuscation tools available.