public void Main()
 {
     try
     {
         //Create invocationManager, a tool to instanciate classes remotely in a disposable AppDomain
         using (Remoting.InvocationManager invocationManager = new Remoting.InvocationManager())
         {
             //The assembly (dll or exe) containing our class
             string assemblyFile = @"C:\DEV\DllTestBed\SampleDlls\NotStrongNamedAssemblyDependentDll.dll";
             //Namespace.ClassName inside the assembly
             string typeName = "NotStrongNamedAssemblyDependentDll.Class1";
             List<string> assembliesLookupPaths = new List<string>();
             //Look for assemblies referenced by assemblyFile in the following directory (there can be more)
             assembliesLookupPaths.Add(@"C:\DEV\DllTestBed\Another folder somewhere");
             //Instanciate our NotStrongNamedAssemblyDependentDll.Class1 in a disposable Appdomain (born in invocationManager):
             Remoting.IRemote remoteObject1 = invocationManager.InstanciateRemotely(assemblyFile, typeName, null, assembliesLookupPaths.ToArray());
             object[] constructorParameters = new object[1];
             constructorParameters[0] = 5;
             string randomString = (string) invocationManager.Invoke(remoteObject1, "GetRandomString", constructorParameters);
             //Now the assembly referenced by assemblyFile is locked.
             MessageBox.Show("NotStrongNamedAssemblyDependentDll generated string: " + randomString);
         }
         //Now the assembly referenced by assemblyFile is unlocked, and can be overwritten without exiting Mercator!
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Пример #2
0
 private void buttonRun2_Click(object sender, EventArgs e)
 {
     //Creating and Using Strong-Named Assemblies: http://msdn.microsoft.com/en-us/library/xwb8f617.aspx
     //Dot NET Assemblies and Strong Name Signature: http://resources.infosecinstitute.com/dot-net-assemblies-and-strong-name-signature/
     try
     {
         using (Remoting.InvocationManager invocationManager = new Remoting.InvocationManager())
         {
             string assemblyFile = @"C:\DEV\DllTestBed\SampleDlls\StrongNamedAssemblyDependentDll.dll";
             string typeName = "StrongNamedAssemblyDependentDll.Class1";
             List<string> assembliesLookupPaths = new List<string>();
             assembliesLookupPaths.Add(@"C:\DEV\DllTestBed\Another folder somewhere");
             Remoting.IRemote remoteObject = invocationManager.InstanciateRemotely(assemblyFile, typeName, null, assembliesLookupPaths.ToArray());
             bool answer = (bool)invocationManager.Invoke(remoteObject, "StrongNamedAssemblyCall", null);
             MessageBox.Show("Réponse: " + answer.ToString());
             //The second call will, as expected, not have to load the assembly in the disposableAppDomain again
             //Remoting.IRemote remoteObject2 = invocationManager.InstanciateRemotely(assemblyFile, typeName, null, assembliesLookupPaths.ToArray());
             //bool answer2 = (bool)invocationManager.Invoke(remoteObject2, "StrongNamedAssemblyCall", null);
             //MessageBox.Show("Réponse: " + answer2.ToString());
         }
         //Some strongly named assemblies (MercatorTunnel.dll, ...) stay locked while used through the debugged application in Visual Studio,
         //but not when used through the same application launched normally.
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Пример #3
0
 private void buttonRun_Click(object sender, EventArgs e)
 {
     try
     {
         using (Remoting.InvocationManager invocationManager = new Remoting.InvocationManager(/*dllRootProbingDirectory, dllProbingDirectories.ToArray()*/))
         {
             string assemblyFile = @"C:\DEV\DllTestBed\SampleDlls\NotStrongNamedAssemblyDependentDll.dll";
             string typeName = "NotStrongNamedAssemblyDependentDll.Class1";
             List<string> assembliesLookupPaths = new List<string>();
             assembliesLookupPaths.Add(@"C:\DEV\DllTestBed\Another folder somewhere");
             Remoting.IRemote remoteObject1 = invocationManager.InstanciateRemotely(assemblyFile, typeName, null, assembliesLookupPaths.ToArray());
             object[] constructorParameters = new object[1];
             constructorParameters[0] = 5;
             string randomString = (string)invocationManager.Invoke(remoteObject1, "GetRandomString", constructorParameters);
             MessageBox.Show("NotStrongNamedAssemblyDependentDll generated string: " + randomString);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }