Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I supose you'll need to load a separate assembly with it's own .config file, no? One way i do that is to load the assembly in a new AppDomain. You'll could deploy that assembly in a separate folder with all his needed references.</p> <p>First setup the AppDomain, here you have a method:</p> <pre><code>AppDomain getAppDomainForAssembly(string assemblypath, string appdomainname) { //this._assembly_file = AssemblyFile; string _assembly_file_name = System.IO.Path.GetFileName(assemblypath); string _rootpath = System.IO.Path.GetDirectoryName(assemblypath); //this._assembly_class_name = AssemblyClassNameToInstance; AppDomainSetup _app_domain_info = new AppDomainSetup(); _app_domain_info.ApplicationBase = _rootpath; _app_domain_info.PrivateBinPath = _rootpath; _app_domain_info.PrivateBinPathProbe = _rootpath; _app_domain_info.ConfigurationFile = _rootpath + @"\app.config"; //Here put the path to the correct .assembly .config file AppDomain _app_domain = AppDomain.CreateDomain( appdomainname, null, _app_domain_info); return _app_domain; } </code></pre> <p>Then get an instance of the object that executes the method on the assembly:</p> <pre><code>protected System.Reflection.Assembly _asm_resolve(string assemblyFile) { return System.Reflection.Assembly.LoadFrom(assemblyFile); } object getInstanceFromAppDomain(ref AppDomain appDomain, string assemblyPath, string className = null) { if (string.IsNullOrEmpty(className)) { System.Reflection.Assembly assembly = _asm_resolve(assemblyPath); System.Reflection.MethodInfo method = assembly.EntryPoint; return appDomain.CreateInstanceFromAndUnwrap(assemblyPath, method.Name); } else { return appDomain.CreateInstanceFromAndUnwrap(assemblyPath, className); } } </code></pre> <p>Even if we know the Object Type, we could create a method with generic type:</p> <pre><code>T getInstanceFromAppDomain&lt;T&gt;(ref AppDomain appDomain, string assemblyPath, string className = null) { if (string.IsNullOrEmpty(className)) { System.Reflection.Assembly assembly = _asm_resolve(assemblyPath); System.Reflection.MethodInfo method = assembly.EntryPoint; return (T)appDomain.CreateInstanceFromAndUnwrap(assemblyPath, method.Name); } else { return (T)appDomain.CreateInstanceFromAndUnwrap(assemblyPath, className); } } </code></pre> <p>And then, invoke the method on the created instance, wich is executing in the new appDomain:</p> <pre><code>void executeMethod(Type objecttype, string methodname, ref object instancedObject, object[] methodparams) { objecttype.InvokeMember( methodname, System.Reflection.BindingFlags.InvokeMethod, null, instancedObject, methodparams); } </code></pre> <p>You could use like this:</p> <pre><code>AppDomain newappdomain = getAppDomainForAssembly(filePath, "Loaded.exe.domain"); object loadedexe_object = getInstanceFromAppDomain(ref newappdomain, filePath); //If you know the method name to call... executeMethod(loadedexe_object.GetType(), "methodname", ref loadedexe_object, null); //or get entry point... executeMethod(loadedexe_object.GetType(), _asm_resolve(filePath).EntryPoint.Name, ref loadedexe_object, null); </code></pre> <p>For the second question, you could use NamedPipes, Remoting, WCF... You need to implement interprocess communication on the same machine. Take a look at MSDN documentaion, code sample covering this scenario with WCF <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.aspx</a></p> <p>See this sample on CodeProject, using Remoting <a href="http://tech.pro/tutorial/633/interprocess-communication-using-named-pipes-in-csharp" rel="nofollow">Inter-process communication via Remoting</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload