Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Reflection;
- using System.Runtime.InteropServices;
- namespace DataStripper
- {
- [SerializableAttribute]
- [ComVisibleAttribute(true)]
- class ProxyDomain : MarshalByRefObject
- {
- private object _instance;
- public object Instance
- {
- get { return _instance; }
- }
- /*private AppDomain _domain;
- public AppDomain Domain
- {
- get
- {
- return _domain;
- }
- }*/
- public AppDomain CreateDomain(string friendlyName, System.Security.Policy.Evidence securityinfo)
- {
- return AppDomain.CreateDomain(friendlyName, securityinfo);
- }
- public void UnloadDomain(AppDomain _domain)
- {
- try
- {
- AppDomain.Unload(_domain);
- }
- catch (ArgumentNullException dne)
- {
- // ignore null exceptions
- return;
- }
- }
- private Assembly _assembly;
- public Assembly Assembly
- {
- get
- {
- return _assembly;
- }
- }
- private byte[] loadFile(string filename)
- {
- FileStream fs = new FileStream(filename, FileMode.Open);
- byte[] buffer = new byte[(int)fs.Length];
- fs.Read(buffer, 0, buffer.Length);
- fs.Close();
- return buffer;
- }
- public void LoadAssembly(AppDomain _domain, string path, string typeName)
- {
- try
- {
- if (_domain == null)
- throw new ArgumentNullException("_domain does not exist.");
- byte[] Assembly_data = loadFile(path);
- byte[] Symbol_data = loadFile(path.Replace(".dll", ".pdb"));
- //_assembly = _domain.Load(Assembly_data, Symbol_data);
- _assembly = _domain.Load(AssemblyName.GetAssemblyName(path));
- _type = _assembly.GetType(typeName);
- _instance = (object)_domain.CreateInstanceAndUnwrap(
- _assembly.FullName,
- typeName);
- }
- catch (Exception ex)
- {
- throw new InvalidOperationException(ex.ToString());
- }
- }
- private Type _type;
- public Type Type
- {
- get
- {
- return _type;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment