c# - Load interface from remote assembly -


I am currently developing a client-server application, it should load the interface from the module and show it inside my window needed. But sometimes I need to plug the remote module. Can I run the module on the module without loading the module file (working with all functions)? Thank you.

Yes, you can load the assembly sent from a remote computer (I do not discuss here I will want to - about the implications of security, at least - check a signature):

  var data = new webmail Download Data Data (URL); // For example ... var assembly = assembly.Load (data);   

In C ++ / CLI (it is not clear in your question what language you are using):

  array < Byte & gt; ^ Data = (gcnew WebClient ()) - & gt; DownloadData (URL); Assembly ^ assembly = assembly :: load (data);   

You now have a assembly and you can load something from it, for example (for example):

  var plugins = assembly. GetExportedTypes () Where (x = & gt; type my (IYourContract) .IsAssignableFrom (x) & amp; amp;; x.IsAbstract). Select (x => (IYourContract Catalyst. CreateInstance (x));   

Please note that this is a very simple implementation because each instance will be different (if you load the same plugin multiple times) and also in the context of these resources (primary memory) Is huge. You should keep a assembly cache:

  Private static dictionary & lt; String, assembly & gt; _cachedAssemblies = new dictionary & lt; String, assembly & gt; (); Public static assembly LoadRemoteAssembly (string url) {lock (_cachedAssemblies) {if (_cachedAssemblies.ContainsKey (url)) back _cachedAssemblies [url]; var data = new WebClient.DownloadData (url); // For example ... var assembly = assembly.Load (data); _cachedAssemblies.Add (URL, assembly); Return assembly; }}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -