本文整理汇总了C#中System.AppDomain.CreateInstanceFromAndUnwrap方法的典型用法代码示例。如果您正苦于以下问题:C# AppDomain.CreateInstanceFromAndUnwrap方法的具体用法?C# AppDomain.CreateInstanceFromAndUnwrap怎么用?C# AppDomain.CreateInstanceFromAndUnwrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.AppDomain
的用法示例。
在下文中一共展示了AppDomain.CreateInstanceFromAndUnwrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
static void Load()
{
if (AppDomain.CurrentDomain.FriendlyName != "OnlineVideosSiteUtilDlls")
{
if (_useSeperateDomain)
{
_domain = AppDomain.CreateDomain("OnlineVideosSiteUtilDlls", null, null, null, true);
// we need to subscribe to AssemblyResolve on the MP2 AppDomain because OnlineVideos.dll is loaded in the LoadFrom Context
// and when unwrapping transparent proxy from our AppDomain, resolving types will fail because it looks only in the default Load context
// we simply help .Net by returning the already loaded assembly from the LoadFrom context
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
_pluginLoader = (PluginLoader)_domain.CreateInstanceFromAndUnwrap(
Assembly.GetExecutingAssembly().Location,
typeof(PluginLoader).FullName);
AppDomain.CurrentDomain.AssemblyResolve -= AssemblyResolve;
_domain.SetData(typeof(PluginLoader).FullName, _pluginLoader);
}
else
{
_domain = AppDomain.CurrentDomain;
_pluginLoader = new PluginLoader();
}
}
else
{
_domain = AppDomain.CurrentDomain;
_pluginLoader = (PluginLoader)AppDomain.CurrentDomain.GetData(typeof(PluginLoader).FullName);
}
}
示例2: ProcessAssembly
public void ProcessAssembly(string filename)
{
FileInfo fileInfo = new FileInfo(filename);
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = fileInfo.DirectoryName;
setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory;
setup.ApplicationName = "Loader";
setup.ShadowCopyFiles = "true";
try
{
appDomain = AppDomain.CreateDomain("Loading Domain", null, setup);
AssemblyProcessor processor = (AssemblyProcessor)
appDomain.CreateInstanceFromAndUnwrap(
"TestAssembly.dll",
"TestAssembly.AssemblyProcessor");
string name = fileInfo.Name.Replace(fileInfo.Extension, "");
Console.WriteLine(name);
processor.Load(name);
processor.Process();
}
finally
{
if (appDomain != null)
{
AppDomain.Unload(appDomain);
appDomain = null;
}
}
}
示例3: SetUp
public void SetUp()
{
string path = new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath;
_localDomain = AppDomain.CreateDomain("NewDomain");
_localDomain.Load(typeof(DataAccessor).Assembly.GetName());
_localTest = (DataAccessorBuilderTest)_localDomain.CreateInstanceFromAndUnwrap(path, GetType().FullName);
}
示例4: InitDomain
private void InitDomain(string name, AppDomainSetup setup)
{
#if STATIC
#else
_currDomain = AppDomain.CreateDomain(name, null, setup);
var type = typeof(ScriptDomainContext);
_context = (ScriptDomainContext)_currDomain.CreateInstanceFromAndUnwrap(type.Assembly.GetName().CodeBase, type.FullName);
#endif
}
示例5: MathAssembly
public MathAssembly(string expression, string variable)
{
var mathAssembly = new MathFuncAssemblyCecil();
_fileName = "MathFuncLib" + "_" + GenerateRandomString(6) + ".dll";
mathAssembly.CompileFuncAndDerivative(expression, variable, "", _fileName);
_domain = AppDomain.CreateDomain("MathFuncDomain");
_mathFuncObj = _domain.CreateInstanceFromAndUnwrap(_fileName, mathAssembly.NamespaceName + "." + mathAssembly.ClassName);
var mathFuncObjType = _mathFuncObj.GetType();
FuncMethodInfo = mathFuncObjType.GetMethod(mathAssembly.FuncName);
FuncDerivativeMethodInfo = mathFuncObjType.GetMethod(mathAssembly.FuncDerivativeName);
}
示例6: GetDomain
RemoteSetupDomain GetDomain ()
{
lock (this) {
if (useCount++ == 0) {
AppDomain.CurrentDomain.AssemblyResolve += MonoAddinsAssemblyResolve;
domain = AppDomain.CreateDomain ("SetupDomain", null, AppDomain.CurrentDomain.SetupInformation);
var type = typeof(RemoteSetupDomain);
remoteSetupDomain = (RemoteSetupDomain) domain.CreateInstanceFromAndUnwrap (type.Assembly.Location, type.FullName);
}
return remoteSetupDomain;
}
}
示例7: CreateAssemblyLoader
public static AssemblyLoader CreateAssemblyLoader(AppDomain appDomain) {
try {
var assemblyLoader = appDomain.CreateInstanceFromAndUnwrap(
typeof(AssemblyLoader).Assembly.CodeBase,
typeof(AssemblyLoader).FullName);
return assemblyLoader as AssemblyLoader;
}
catch (Exception ex) {
Debug.WriteLine(ex);
return null;
}
}
示例8: Create
public ILoader Create()
{
AppDomainSetup adSetup = new AppDomainSetup();
adSetup.ShadowCopyFiles = "true"; // not a boolean
m_LoaderDomain = createAppDomainForLoader(adSetup);
string dir = m_LoaderDomain.SetupInformation.ApplicationBase;
string selfAssemblyName = (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath;
ILoader loader = (ILoader) m_LoaderDomain.CreateInstanceFromAndUnwrap(selfAssemblyName, "Cider_x64.Loader");
return loader;
}
示例9: AssemblyExecutor
public AssemblyExecutor(string fileNname, string domainName)
{
assemblyFileName = fileNname;
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = Path.GetDirectoryName(assemblyFileName);
setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory;
setup.ApplicationName = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
setup.ShadowCopyFiles = "true";
setup.ShadowCopyDirectories = Path.GetDirectoryName(assemblyFileName);
appDomain = AppDomain.CreateDomain(domainName, null, setup);
remoteExecutor = (RemoteExecutor)appDomain.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location, typeof(RemoteExecutor).ToString());
}
示例10: Create
public ILoader Create()
{
AppDomainSetup adSetup = new AppDomainSetup();
adSetup.ShadowCopyFiles = "true"; // not a boolean
m_LoaderDomain = createAppDomainForLoader(adSetup);
string dir = m_LoaderDomain.SetupInformation.ApplicationBase;
string selfAssemblyName = (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath;
selfAssemblyName = Uri.UnescapeDataString(selfAssemblyName); // e.g. otherwise, spaces in the path of our .EXE would be represented as '%20'
ILoader loader = (ILoader) m_LoaderDomain.CreateInstanceFromAndUnwrap(selfAssemblyName, "Cider_x64.Loader");
return loader;
}
示例11: CreateSiloHost
private static SiloHost CreateSiloHost(AppDomain appDomain, ClusterConfiguration clusterConfig)
{
var args = new object[] { nameof(SiloInitializationIsRetryableTest), clusterConfig };
return (SiloHost)appDomain.CreateInstanceFromAndUnwrap(
"OrleansRuntime.dll",
typeof(SiloHost).FullName,
false,
BindingFlags.Default,
null,
args,
CultureInfo.CurrentCulture,
new object[] { });
}
示例12: CreateAgent
private static DomainHostingStarterAgent CreateAgent(AppDomain domain)
{
try
{
return (DomainHostingStarterAgent)domain.CreateInstanceAndUnwrap(
typeof(DomainHostingStarterAgent).Assembly.FullName,
typeof(DomainHostingStarterAgent).FullName);
}
catch
{
return (DomainHostingStarterAgent)domain.CreateInstanceFromAndUnwrap(
typeof(DomainHostingStarterAgent).Assembly.Location,
typeof(DomainHostingStarterAgent).FullName);
}
}
示例13: Load
// Methods ========================================================================
public void Load(string filePath)
{
AssemblyPath = filePath;
AssemblyName = Path.GetFileName(filePath);
domain = AppDomain.CreateDomain(AssemblyName);
proxy = (AppDomainProxy)domain.CreateInstanceFromAndUnwrap(
Assembly.GetExecutingAssembly().CodeBase, typeof(AppDomainProxy).FullName);
try {
proxy.LoadAssembly(filePath);
} catch (Exception) {
AppDomain.Unload(domain);
throw;
}
}
示例14: RecyclableAppDomain
public RecyclableAppDomain (string name)
{
var info = new AppDomainSetup () {
//appbase needs to allow loading this assembly, for remoting
ApplicationBase = System.IO.Path.GetDirectoryName (typeof (TemplatingAppDomainRecycler).Assembly.Location),
DisallowBindingRedirects = false,
DisallowCodeDownload = true,
DisallowApplicationBaseProbing = false,
ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
};
domain = AppDomain.CreateDomain (name, null, info);
var t = typeof(DomainAssemblyLoader);
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
assemblyMap = (DomainAssemblyLoader) domain.CreateInstanceFromAndUnwrap(t.Assembly.Location, t.FullName);
AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
domain.AssemblyResolve += assemblyMap.Resolve;// new DomainAssemblyLoader(assemblyMap).Resolve;
}
示例15: EfMigrator
public EfMigrator(string assemblyPath, string qualifiedDbConfigName, string appConfigPath, string connectionString, string connectionProvider,
ILogger logger)
{
_logger = logger;
appConfigPath = Path.GetFullPath(appConfigPath);
if (!File.Exists(appConfigPath))
{
throw new EfMigrationException($"The {nameof(appConfigPath)} '{appConfigPath}' must exist.");
}
var domainSetup = AppDomain.CurrentDomain.SetupInformation;
domainSetup.ConfigurationFile = appConfigPath;
_logger.Debug($"Prepared AppDomain setup using {appConfigPath} as the appconfig.");
var domainName = $"EfMigrator:{Guid.NewGuid()}";
_domain = AppDomain.CreateDomain(domainName, null, domainSetup);
_logger.Debug($"Created new AppDomain named {domainName}.");
var type = typeof(EfMigratorBackend);
var fullPath = Assembly.GetAssembly(typeof(EfMigratorBackend)).Location;
//var domain = AppDomain.CurrentDomain.GetAssemblies()
// .Where(x => !x.IsDynamic)
// .Where(x => !x.GlobalAssemblyCache)
// .Select(x => Path.GetDirectoryName(x.Location))
// .Distinct();
//var domains = string.Join(", ", domain);
//logger.Debug($"Loading assemblies into appDomain: {domains}.");
Debug.Assert(fullPath != null, "fullPath != null");
var migrator = (EfMigratorBackend) _domain.CreateInstanceFromAndUnwrap(fullPath, type.FullName);
_logger.Debug("Created new instance.");
migrator.Initialize(assemblyPath, qualifiedDbConfigName, connectionString, connectionProvider);
_logger.Debug($"Initialized new {nameof(EfMigratorBackend)} within {domainName}.");
CurrentMigration = migrator.GetCurrentMigration() ?? InitialDatabase;
var currentMigrationStr = CurrentMigration == InitialDatabase ? "$InitialDatabase" : CurrentMigration;
_logger.Information($"Current Migration is {currentMigrationStr}.");
_migratorBackend = migrator;
}