Just something I experimented with for fun and it was pretty cool and if used correct it would be nice.
So what I did was just making a really simple wrapper to add libraries into a collection and then just executing.
What you can do with this is having your libraries online, instead located on the machine with the executable.
All it does is just downloading the bytes of the dll online and then putting it into a collection where it's just invoking the method using the Assembly class. You can always make this more advanced as I just used the Invoke method as a test.
WebLibrary class:
Examlple usage:
Dll.dll:
Screenshot:
Spoiler (Click to View)
I think that's it.
🤝
Note: The namespace has to be the same as the assembly name.
So what I did was just making a really simple wrapper to add libraries into a collection and then just executing.
What you can do with this is having your libraries online, instead located on the machine with the executable.
All it does is just downloading the bytes of the dll online and then putting it into a collection where it's just invoking the method using the Assembly class. You can always make this more advanced as I just used the Invoke method as a test.
WebLibrary class:
Code
public class WebLibrary
{
private Dictionary<string, byte[]> libCollection;
private string webUrl;
public WebLibrary(Uri webUri)
{
webUrl = webUri.ToString();
libCollection = new Dictionary<string, byte[]>();
}
public WebLibrary(string webUrl)
{
this.webUrl = webUrl;
libCollection = new Dictionary<string, byte[]>();
}
public void Add(string LibraryName)
{
WebClient wc = new WebClient();
byte[] data = wc.DownloadData(webUrl.EndsWith("/") ? webUrl + LibraryName + ".dll" : webUrl + "/" + LibraryName + ".dll");
libCollection.Add(LibraryName, data);
}
public void InvokeMethod(string LibraryName, string Class, string MethodName, object[] Parameters = null)
{
Assembly.Load(libCollection[LibraryName])
.GetType(LibraryName + "." + Class).GetMethod(MethodName).Invoke(null, Parameters);
}
}Examlple usage:
Code
WebLibrary webLib = new WebLibrary("http://127.0.0.1/");//Initializing the web-library.
webLib.Add("Dll");//This will download the bytes from http://127.0.0.1/Dll.dll and store them in a dictionary with "Dll" as key.
webLib.InvokeMethod("Dll", "TestClass", "MessageBox", new object[] { "Test Message!" });//This will invoke the method "MessageBox" in the class "TestClass" under the namespace "Dll" with the parameters "Test Message!".Dll.dll:
Code
namespace Dll
{
public class TestClass
{
public static void MessageBox(string message)
{
System.Windows.Forms.MessageBox.Show(message);
}
}
}Screenshot:
Spoiler (Click to View)
I think that's it.
🤝
Note: The namespace has to be the same as the assembly name.

