本文整理汇总了C#中System.AppDomain.CreateInstance方法的典型用法代码示例。如果您正苦于以下问题:C# AppDomain.CreateInstance方法的具体用法?C# AppDomain.CreateInstance怎么用?C# AppDomain.CreateInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.AppDomain
的用法示例。
在下文中一共展示了AppDomain.CreateInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: APIWrapper
static APIWrapper()
{
_domain = AppDomain.CreateDomain("OPEN_TERRARIA_API_WRAPPER", null /*AppDomain.CurrentDomain.Evidence*/, new AppDomainSetup()
{
//ShadowCopyFiles = "false",
ApplicationBase = Environment.CurrentDirectory/*, Commented out as OSX does not have this?
AppDomainManagerAssembly = String.Empty*/
});
var type = typeof(Proxy);
foreach (var file in new string[] { "Patcher.exe", "OTA.dll" })
{
if (!System.IO.File.Exists(file))
{
var bin = System.IO.Path.Combine(Environment.CurrentDirectory, "bin", "x86", "Debug", file);
if (System.IO.File.Exists(bin))
{
System.IO.File.Copy(bin, file);
Console.WriteLine("Copied: " + file);
}
}
}
var plugin = _domain.CreateInstance(type.Assembly.FullName, type.FullName);
_api = plugin.Unwrap() as Proxy;
_api.Load(System.IO.Path.Combine(Environment.CurrentDirectory, "OTA.dll"));
}
示例2: CreateRemoteContainer
protected IWindsorContainer CreateRemoteContainer(AppDomain domain, String configFile)
{
ObjectHandle handle = domain.CreateInstance(
typeof(WindsorContainer).Assembly.FullName,
typeof(WindsorContainer).FullName, false, BindingFlags.Instance|BindingFlags.Public, null,
new object[] { configFile },
CultureInfo.InvariantCulture, null, null );
return (IWindsorContainer) handle.Unwrap();
}
示例3: GetRemoteContainer
protected IWindsorContainer GetRemoteContainer(AppDomain domain, String configFile)
{
ObjectHandle handle = domain.CreateInstance(
typeof(ContainerPlaceHolder).Assembly.FullName,
typeof(ContainerPlaceHolder).FullName, false, BindingFlags.Instance|BindingFlags.Public, null,
new object[] { configFile },
CultureInfo.InvariantCulture, null, null );
ContainerPlaceHolder holder = handle.Unwrap() as ContainerPlaceHolder;
return holder.Container;
}
示例4: LoadAssembly
internal static IAssembly LoadAssembly(string path, AppDomain domain)
{
if (domain != AppDomain.CurrentDomain) {
var crossDomainAssembly = domain.CreateInstance<RemoteAssembly>();
crossDomainAssembly.Load(path);
return crossDomainAssembly;
}
var assembly = new RemoteAssembly();
assembly.Load(path);
return assembly;
}
示例5: APIWrapper
static APIWrapper()
{
//_domain = AppDomain.CreateDomain("TDSM_API_WRAPPER", AppDomain.CurrentDomain.Evidence, new AppDomainSetup()
//{
// //ShadowCopyFiles = "false",
// ApplicationBase = Environment.CurrentDirectory
//});
_domain = AppDomain.CreateDomain("OPEN_TERRARIA_API_WRAPPER", null /*AppDomain.CurrentDomain.Evidence*/, new AppDomainSetup()
{
//ShadowCopyFiles = "false",
ApplicationBase = Environment.CurrentDirectory/*, Commented out as OSX does not have this?
AppDomainManagerAssembly = String.Empty*/
});
//Console.WriteLine("Domain: " + ((_domain == null) ? "null" : "not null"));
//_domain.AssemblyResolve += (s, a) =>
//{
// try
// {
// //return Assembly.LoadFrom(Path.Combine(Globals.PluginPath, a.Name + ".dll"));
// }
// catch { }
// return null;
//};
var type = typeof(Proxy);
foreach (var file in new string[] { "Patcher.exe", "OTA.dll" })
{
if (!System.IO.File.Exists(file))
{
var bin = System.IO.Path.Combine(Environment.CurrentDirectory, "bin", "x86", "Debug", file);
if (System.IO.File.Exists(bin))
{
System.IO.File.Copy(bin, file);
Console.WriteLine("Copied: " + file);
}
}
}
var plugin = _domain.CreateInstance(type.Assembly.FullName, type.FullName);
// var r = plugin.CreateObjRef(typeof(MarshalByRefObject));
////var p = r.GetRealObject(new System.Runtime.Serialization.StreamingContext( System.Runtime.Serialization.StreamingContextStates.CrossAppDomain));
_api = plugin.Unwrap() as Proxy;
_api.Load(System.IO.Path.Combine(Environment.CurrentDirectory, "OTA.dll"));
//var has = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.GetName().Name == "TDSM.API").Count() > 0;
//var asm = _domain.GetAssemblies();
}
示例6: CreateInstance
/// <summary>
/// Returns a RemoteTestRunner in the target domain. This method
/// is used in the domain that wants to get a reference to
/// a RemoteTestRunnner and not in the test domain itself.
/// </summary>
/// <param name="targetDomain">AppDomain in which to create the runner</param>
/// <param name="ID">Id for the new runner to use</param>
/// <returns></returns>
public static RemoteTestRunner CreateInstance(AppDomain targetDomain, int ID)
{
#if NET_2_0
System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstance(
targetDomain,
#else
System.Runtime.Remoting.ObjectHandle oh = targetDomain.CreateInstance(
#endif
Assembly.GetExecutingAssembly().FullName,
typeof(RemoteTestRunner).FullName,
false, BindingFlags.Default, null, new object[] { ID }, null, null, null);
object obj = oh.Unwrap();
return (RemoteTestRunner)obj;
}
示例7: CreateInstance
/// <summary>
/// Factory method used to create a DomainAgent in an AppDomain.
/// </summary>
/// <param name="targetDomain">The domain in which to create the agent</param>
/// <param name="traceLevel">The level of internal tracing to use</param>
/// <returns>A proxy for the DomainAgent in the other domain</returns>
static public DomainAgent CreateInstance(AppDomain targetDomain)
{
#if CLR_2_0 || CLR_4_0
System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstance(
targetDomain,
#else
System.Runtime.Remoting.ObjectHandle oh = targetDomain.CreateInstance(
#endif
Assembly.GetExecutingAssembly().FullName,
typeof(DomainAgent).FullName,
false, BindingFlags.Default, null, null, null, null, null);
object obj = oh.Unwrap();
return (DomainAgent)obj;
}
示例8: InstantiateDecimal
static object InstantiateDecimal(AppDomain appDomain, Binder binder, CultureInfo cultureInfo, string UName, string P2PUri)
{
try
{
object instance = appDomain.CreateInstance(
"ImageSharing.Presentation",
"ImageSharing.Presentation.P2PImageSharingClient",
false,
BindingFlags.Default,
binder,
new object[] { UName, P2PUri },
cultureInfo,
null,
null
);
return instance;
}
catch (Exception exp)
{
VMuktiHelper.ExceptionHandler(exp, "InstantiateDecimal", "P2PImageSharingDummyClient.cs");
return null;
}
}
示例9: InstantiateQA
static object InstantiateQA(AppDomain appDomain, Binder binder, CultureInfo cultureInfo, string MyName, string UName, int Id, string netP2pUri, string httpUri)
{
try
{
object instance = appDomain.CreateInstance(
"QA.Presentation",
"QA.Presentation.QADummy",
false,
BindingFlags.Default,
binder,
new object[] { MyName, UName, Id, netP2pUri, httpUri },
cultureInfo,
null,
null
);
return instance;
}
catch (Exception exp)
{
return null;
}
}
示例10: Start
public void Start()
{
_Domain = AppDomain.CreateDomain(_Setup.ApplicationName, null, _Setup);
// Construct the target class, it must take over from there.
_RemoteType = _Domain.CreateInstance(_TypeInfo[1], _TypeInfo[0]);
}
示例11: CreateTestRunner
private RemoteTestRunner CreateTestRunner(AppDomain domain)
{
ObjectHandle oh;
Type rtrType = typeof(RemoteTestRunner);
#if NET_4_0
oh = domain.CreateInstance(
rtrType.Assembly.FullName,
rtrType.FullName,
false,
BindingFlags.Public | BindingFlags.Instance,
null,
null,
CultureInfo.InvariantCulture,
null);
#else
oh = domain.CreateInstance(
rtrType.Assembly.FullName,
rtrType.FullName,
false,
BindingFlags.Public | BindingFlags.Instance,
null,
null,
CultureInfo.InvariantCulture,
null,
AppDomain.CurrentDomain.Evidence);
#endif
return (RemoteTestRunner) oh.Unwrap();
}
示例12: InitializeKeyCheck
//**************************************************************
// InitializeKeyCheck()
//**************************************************************
public void InitializeKeyCheck()
{
//Clear any previous app domain
UnInitializeKeyCheck();
AD = AppDomain.CreateDomain("KeyValidatorDomain");
BindingFlags flags = (BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance);
ObjectHandle objh = AD.CreateInstance( "AppUpdater", "Microsoft.Samples.AppUpdater.KeyValidator", false,
flags, null, null, null, null, null);
// Unwrap the object
Object obj = objh.Unwrap();
// Cast to the actual type
Validator = (KeyValidator)obj;
KeyList = GetKeyList(AppUrl.TrimEnd(new char[] {'/'}) + "/" + KEYFILENAME);
}
示例13: CreateAppDomain
/// <summary>
/// Initialize the AppDomain and load the types of the dll
/// </summary>
/// <returns>the types of the dll</returns>
public void CreateAppDomain()
{
string currentDirectory = Environment.CurrentDirectory;
string cachePath = Path.Combine(
currentDirectory,
"__cache");
PermissionSet permissionSet = new PermissionSet(PermissionState.Unrestricted);
AppDomainSetup appDomainSetup = new AppDomainSetup
{
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
ShadowCopyFiles = "true",
CachePath = cachePath
};
_testsDomain = AppDomain.CreateDomain("TestDomain", null, appDomainSetup, permissionSet);
try
{
ITypesLoaderFactory typesLoaderFactory = (ITypesLoaderFactory)_testsDomain.CreateInstance(Assembly.GetExecutingAssembly().FullName, " RegTesting.Tests.Core.TypesLoaderFactory").Unwrap();
object[] constructArgs = new object[] { };
ITypesLoader typesLoader = typesLoaderFactory.Create(Assembly.GetExecutingAssembly().FullName, " RegTesting.Tests.Core.TypesLoader", constructArgs);
Types = typesLoader.GetTypes(_testsFile);
}
catch (NullReferenceException)
{
}
}
示例14: LoadTypes
/// <summary>
/// Initialize the AppDomain and load the types of the dll
/// </summary>
/// <returns>the types of the dll</returns>
public string[] LoadTypes()
{
string environmentPath = Environment.CurrentDirectory;
string cachePath = Path.Combine(environmentPath,"__cache");
PermissionSet permissionSet = new PermissionSet(PermissionState.Unrestricted);
AppDomainSetup appDomainSetup = new AppDomainSetup
{
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
ShadowCopyFiles = "true",
CachePath = cachePath
};
_testsDomain = AppDomain.CreateDomain("TestDomain", null, appDomainSetup, permissionSet);
try
{
ITypesLoaderFactory typesLoaderFactory = (ITypesLoaderFactory)_testsDomain.CreateInstance(Assembly.GetExecutingAssembly().FullName, "RegTesting.Tests.Core.TypesLoaderFactory").Unwrap();
object[] constructArgs = new object[] {};
ITypesLoader typesLoader = typesLoaderFactory.Create(Assembly.GetExecutingAssembly().FullName, "RegTesting.Tests.Core.TypesLoader", constructArgs);
Types = typesLoader.GetTypes(_testsFile);
foreach (string type in Types)
{
if (type.StartsWith("ERROR:"))
{
Console.WriteLine(type);
}
}
return Types;
}
catch (NullReferenceException)
{
//No types found for this branch
return new string[0];
}
catch (ReflectionTypeLoadException reflectionTypeLoadException)
{
StringBuilder stringBuilder = new StringBuilder();
foreach (Exception exSub in reflectionTypeLoadException.LoaderExceptions)
{
stringBuilder.AppendLine(exSub.Message);
if (exSub is FileNotFoundException)
{
FileNotFoundException fileNotFoundException = exSub as FileNotFoundException;
if (!string.IsNullOrEmpty(fileNotFoundException.FusionLog))
{
stringBuilder.AppendLine("Fusion Log:");
stringBuilder.AppendLine(fileNotFoundException.FusionLog);
}
}
stringBuilder.AppendLine();
}
string errorMessage = stringBuilder.ToString();
Console.WriteLine(errorMessage);
//Display or log the error based on your application.
return new string[0];
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
//No types found for this branch
return new string[0];
}
}
示例15: InstantiateDecimal
//static object InstantiateDecimal(AppDomain appDomain, Binder binder, CultureInfo cultureInfo, string MyName, string UName, int Id, string netP2pUri, string httpUri)
//{
// try
// {
// object instance = appDomain.CreateInstance(
// "Weblink.Presentation",
// "Weblink.Presentation.WebLinkDummies",
// false,
// BindingFlags.Default,
// binder,
// new object[] { MyName, UName, Id, netP2pUri, httpUri },
// cultureInfo,
// null,
// null
// );
// return instance;
// }
// catch (Exception exp)
// {
// System.Windows.MessageBox.Show("InstantiateDecimal" + exp.Message);
// if (exp.InnerException != null)
// {
// System.Windows.MessageBox.Show("InstantiateDecimal " + exp.InnerException.Message);
// }
// throw exp;
// return null;
// }
//}
static object InstantiateDecimal(AppDomain appDomain, Binder binder, CultureInfo cultureInfo, string MyName, string UName, int Id, string netP2pUri, string httpUri)
{
try
{
object instance = appDomain.CreateInstance(
"Video.Presentation",
"Video.Presentation.MainVideoDummies",
false,
BindingFlags.Default,
binder,
new object[] { MyName, UName, Id, netP2pUri, httpUri },
cultureInfo,
null,
null
);
return instance;
}
catch (Exception ex)
{
ex.Data.Add("My Key", "--InstantiateDecimal()---VMukti--:--VmuktiModules--:--Collaborative--:--Video.Presentation--:--MainVideoDummyClient.cs--:");
//ClsException.LogError(ex);
//ClsException.WriteToErrorLogFile(ex);
System.Text.StringBuilder sb = new StringBuilder();
sb.AppendLine(ex.Message);
sb.AppendLine();
sb.AppendLine("StackTrace : " + ex.StackTrace);
sb.AppendLine();
sb.AppendLine("Location : " + ex.Data["My Key"].ToString());
sb.AppendLine();
sb1 = CreateTressInfo();
sb.Append(sb1.ToString());
VMuktiAPI.ClsLogging.WriteToTresslog(sb);
return null;
}
}