本文整理汇总了C#中System.AppDomain.CreateInstanceAndUnwrap方法的典型用法代码示例。如果您正苦于以下问题:C# AppDomain.CreateInstanceAndUnwrap方法的具体用法?C# AppDomain.CreateInstanceAndUnwrap怎么用?C# AppDomain.CreateInstanceAndUnwrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.AppDomain
的用法示例。
在下文中一共展示了AppDomain.CreateInstanceAndUnwrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAppDomain
private ICustomConfigAssemblyInspector CreateAppDomain()
{
AppDomainSetup setup = new AppDomainSetup();
#if DEBUG
setup.ApplicationBase = @"E:\db4object\db4o\Trunk\omn\OMADDIN\bin\";
#else
setup.ApplicationBase = CommonForAppDomain.GetPath() + "\\";
#endif
setup.ShadowCopyDirectories = Path.GetTempPath();
setup.ShadowCopyFiles = "true";
workerAppDomain = AppDomain.CreateDomain("CustomConfigWorkerAppDomain", null, setup);
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
object anObject = workerAppDomain.CreateInstanceAndUnwrap("OMCustomConfigImplementation",
"OMCustomConfigImplementation.CustomConfigAssemblyInfo.CustomConfigAssemblyInspector");
ICustomConfigAssemblyInspector customConfigAssemblyInspector = anObject as ICustomConfigAssemblyInspector;
object anObject1 = workerAppDomain.CreateInstanceAndUnwrap("OMCustomConfigImplementation",
"OMCustomConfigImplementation.UserCustomConfig.UserConfig");
IUserConfig conn = anObject1 as IUserConfig;
CustomConfigInspectorObject.CustomUserConfig = conn;
return customConfigAssemblyInspector;
}
示例2: RunScriptCore
private void RunScriptCore(byte[] inMemoryAssembly, byte[] inMemorySymbolStore, TextWriter outputTextWriter, TextWriter errorTextWriter)
{
RemoteScriptRun scriptRun;
lock (fieldsLock)
{
if (inMemoryAssembly != loadedAssembly)
{
if (scriptAppDomain != null)
{
AppDomain.Unload(scriptAppDomain);
}
scriptAppDomain = AppDomain.CreateDomain("ScriptAppDomain");
remoteScriptRun = (RemoteScriptRun)scriptAppDomain.CreateInstanceAndUnwrap(typeof(RemoteScriptRun).Assembly.FullName, typeof(RemoteScriptRun).FullName);
remoteScriptRun.Load(inMemoryAssembly, inMemorySymbolStore, outputTextWriter, errorTextWriter);
loadedAssembly = inMemoryAssembly;
}
scriptRun = remoteScriptRun;
}
try
{
scriptRun?.Run();
}
catch (AppDomainUnloadedException)
{
}
}
示例3: Start
/// <summary>
/// Starts this instance.
/// </summary>
/// <exception cref="System.InvalidOperationException">Job already started.</exception>
public static void Start()
{
if (_job != null)
throw new InvalidOperationException("Job already started.");
var evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
var setup = new AppDomainSetup
{
ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
ShadowCopyFiles = "false"
};
_appDomain = AppDomain.CreateDomain("eSync-" + Guid.NewGuid(), evidence, setup);
try
{
var assembly = _appDomain.Load(typeof(SyncServiceJob).Assembly.GetName());
var jobTypeName = typeof(SyncServiceJob).FullName;
_job = (IJob)_appDomain.CreateInstanceAndUnwrap(assembly.FullName, jobTypeName);
_job.Start();
}
catch
{
_job = null;
AppDomain.Unload(_appDomain);
_appDomain = null;
throw;
}
}
示例4: RemoteDebugger
public RemoteDebugger()
{
// Create a new debugger session
mSessionId = Guid.NewGuid().ToString();
Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
AppDomainSetup appDomainSetup = AppDomain.CurrentDomain.SetupInformation;
mAppDomain = AppDomain.CreateDomain(String.Format("Debugger-{0}", mSessionId), evidence, appDomainSetup);
/*
Type assemblyLoaderType = typeof(AssemblyLoader);
AssemblyLoader loader = mAppDomain.CreateInstanceAndUnwrap(assemblyLoaderType.Assembly.GetName().Name, assemblyLoaderType.FullName) as AssemblyLoader;
foreach (String assemblyPath in Directory.GetFiles(DebuggerConfig.ApplicationPath, "Tridion*.dll"))
{
loader.LoadAssembly(assemblyPath);
}
*/
Type debuggerHostType = typeof(DebugEngineServer);
mDebuggerHost = mAppDomain.CreateInstanceAndUnwrap(
debuggerHostType.Assembly.GetName().Name,
debuggerHostType.FullName,
true,
BindingFlags.Default,
null,
new Object[] { mSessionId },
null,
null) as DebugEngineServer;
}
示例5: DiaSessionWrapper
public DiaSessionWrapper(string assemblyFilename)
{
session = new DiaSession(assemblyFilename);
var setup = new AppDomainSetup
{
ApplicationBase = Path.GetDirectoryName(new Uri(typeof(DiaSessionWrapperHelper).Assembly.CodeBase).LocalPath),
ApplicationName = Guid.NewGuid().ToString(),
LoaderOptimization = LoaderOptimization.MultiDomainHost,
ShadowCopyFiles = "true",
};
setup.ShadowCopyDirectories = setup.ApplicationBase;
setup.CachePath = Path.Combine(Path.GetTempPath(), setup.ApplicationName);
appDomain = AppDomain.CreateDomain(setup.ApplicationName, null, setup, new PermissionSet(PermissionState.Unrestricted));
helper = (DiaSessionWrapperHelper)appDomain.CreateInstanceAndUnwrap(
assemblyName: typeof(DiaSessionWrapperHelper).Assembly.FullName,
typeName: typeof(DiaSessionWrapperHelper).FullName,
ignoreCase: false,
bindingAttr: 0,
binder: null,
args: new[] { assemblyFilename },
culture: null,
activationAttributes: null,
securityAttributes: null
);
}
示例6: Run
public ContextWrapper Run(string tagOrClassName, RunnerInvocation invocation, Func<RunnerInvocation, ContextWrapper> action, string dll)
{
this.dll = dll;
var setup = new AppDomainSetup();
setup.ConfigurationFile = Path.GetFullPath(config);
setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
domain = AppDomain.CreateDomain("NSpecRunnerDomain.Run", null, setup);
var type = typeof(Wrapper);
var assemblyName = type.Assembly.GetName().Name;
var typeName = type.FullName;
domain.AssemblyResolve += Resolve;
var wrapper = (Wrapper)domain.CreateInstanceAndUnwrap(assemblyName, typeName);
var results = wrapper.Execute(invocation, action);// RunContexts(tagOrClassName);
AppDomain.Unload(domain);
return results;
}
示例7: StartInternal
private void StartInternal()
{
ConfigurationManipulation.RemoveAzureTraceListenerFromConfiguration(_configurationFilePath);
CopyStubAssemblyToRoleDirectory(_appDomainSetup.ApplicationBase, _role);
_appDomain = AppDomain.CreateDomain("LightBlue", null, _appDomainSetup);
_hostStub = (HostStub)_appDomain.CreateInstanceAndUnwrap(typeof(HostStub).Assembly.FullName, typeof(HostStub).FullName);
var shipper = new EventTraceShipper();
Action<string> twh = m => _role.TraceWrite(Identifier, m);
Action<string> twlh = m => _role.TraceWriteLine(Identifier, m);
shipper.TraceWrite += twh;
shipper.TraceWriteLine += twlh;
_hostStub.ConfigureTracing(shipper);
// TODO: decide how this is going to work.
_appDomain.UnhandledException += StubExceptionHandler.Handler;
try
{
_started.SetResult(new object());
_role.TraceWriteLine(Identifier, "Role started in app domain: " + _appDomain.Id + " by " + Thread.CurrentThread.Name);
_hostStub.Run(_assemblyFilePath, _configurationFilePath, _serviceDefinitionFilePath, _roleName, false);
}
catch (Exception ex)
{
_role.TraceWriteLine(Identifier, ex.ToString());
}
finally
{
shipper.TraceWrite -= twh;
shipper.TraceWriteLine -= twlh;
_completed.SetResult(new object());
}
}
示例8: InitliazeValidationAppDomain
private void InitliazeValidationAppDomain()
{
m_ValidationAppDomain = AppDomain.CreateDomain("ValidationDomain", AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.BaseDirectory, string.Empty, false);
var validatorType = typeof(TypeValidator);
m_Validator = (TypeValidator)m_ValidationAppDomain.CreateInstanceAndUnwrap(validatorType.Assembly.FullName, validatorType.FullName);
}
示例9: CustomWindowsFormsHost
/// <summary>
/// Creates a new CustomWindowsFormsHost instance that allows hosting controls
/// from the specified AppDomain.
/// </summary>
public CustomWindowsFormsHost(AppDomain childDomain)
{
var type = typeof(HostedControlContainer);
this._container =
(HostedControlContainer)childDomain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);
Init();
}
示例10: Run
public void Run(RunnerInvocation invocation, Action<RunnerInvocation> action, string dll)
{
this.dll = dll;
var setup = new AppDomainSetup();
setup.ConfigurationFile = Path.GetFullPath(config);
setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
domain = AppDomain.CreateDomain("NSpecDomain.Run", null, setup);
var type = typeof(Wrapper);
var assemblyName = type.Assembly.GetName().Name;
var typeName = type.FullName;
domain.AssemblyResolve += Resolve;
var wrapper = (Wrapper)domain.CreateInstanceAndUnwrap(assemblyName, typeName);
wrapper.Execute(invocation, action);
AppDomain.Unload(domain);
}
示例11: AssertAppDomainHasAssemblyResolveEventSubscribers
internal static void AssertAppDomainHasAssemblyResolveEventSubscribers(int expected, AppDomain appDomain)
{
var proxy = (AppDomainInfoProvider)appDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(AppDomainInfoProvider).FullName);
var subscriberCount = proxy.GetAssemblyResolveEventSubscriberCount();
Assert.Equal(expected, subscriberCount);
}
示例12: LoadFrom
public void LoadFrom(string path)
{
if (_domain != null)
{
_scanner.Teardown();
AppDomain.Unload(_domain);
}
var name = Path.GetFileNameWithoutExtension(path);
var dirPath = Path.GetFullPath(Path.GetDirectoryName(path));
var setup = new AppDomainSetup
{
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
PrivateBinPath = dirPath,
ShadowCopyFiles = "true",
ShadowCopyDirectories = dirPath,
};
_domain = AppDomain.CreateDomain(name + "Domain", AppDomain.CurrentDomain.Evidence, setup);
var scannerType = typeof(Scanner);
_scanner = (Scanner)_domain.CreateInstanceAndUnwrap(scannerType.Assembly.FullName, scannerType.FullName);
_scanner.Load(name);
_scanner.Setup();
}
示例13: Init
void Init(string fileNname, string domainName)
{
//difference comparing to InitLagacy:
// CreateInstanceAndUnwrap instead of CreateInstanceFromAndUnwrap
//
// setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
// instead of setup.ApplicationBase = Path.GetDirectoryName(assemblyFileName);
//
// In 2016 just discovered that InitLegacy doesn't longer work. May be because some changes in .NET versions...
// This is a low impact change as AssemblyExecutor is only used for cached vs. non-cached execution in stand alone
// hosting mode.
assemblyFileName = fileNname;
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory;
setup.ApplicationName = Utils.GetAssemblyFileName(Assembly.GetExecutingAssembly());
setup.ShadowCopyFiles = "true";
setup.ShadowCopyDirectories = Path.GetDirectoryName(assemblyFileName);
appDomain = AppDomain.CreateDomain(domainName, null, setup);
remoteExecutor = (RemoteExecutor)appDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(RemoteExecutor).ToString());
remoteExecutor.searchDirs = ExecuteOptions.options.searchDirs;
}
示例14: Invoke
public static bool Invoke(AppDomain domain, ScriptEnvironmentSetup setup, out RemoteScriptEnvironment environment) {
RemoteDelegate rd = (RemoteDelegate)domain.CreateInstanceAndUnwrap(typeof(RemoteDelegate).Assembly.FullName,
typeof(RemoteDelegate).FullName, false, BindingFlags.Default, null, new object[] { setup }, null, null, null);
environment = rd.Environment;
return rd.NewCreated;
}
示例15: CreateRemoteHost
protected override HostedService CreateRemoteHost(AppDomain appDomain)
{
object instance = appDomain.CreateInstanceAndUnwrap("Rhino.ServiceBus",
"Rhino.ServiceBus.LoadBalancer.LoadBalancerHost");
var hoster = (LoadBalancerHost)instance;
return new HostedService(hoster, "Rhino.ServiceBus", appDomain);
}