本文整理汇总了C#中System.AppDomain.Load方法的典型用法代码示例。如果您正苦于以下问题:C# AppDomain.Load方法的具体用法?C# AppDomain.Load怎么用?C# AppDomain.Load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.AppDomain
的用法示例。
在下文中一共展示了AppDomain.Load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
//включаем визуальные стили для прилжения, поскольку оно является оконным
Application.EnableVisualStyles();
/*создаём необходимые домены приложений с дружественными именами и
* сохраняем ссылки на них в соответствующие переменные*/
Drawer = AppDomain.CreateDomain("Drawer");
TextWindow = AppDomain.CreateDomain("TextWindow");
/*загружаем сборки с оконными приложениями в соответствующие домены приложений*/
DrawerAsm = Drawer.Load(AssemblyName.GetAssemblyName("TextDrawer.exe"));
TextWindowAsm = Drawer.Load(AssemblyName.GetAssemblyName("TextWindow.exe"));
/*создаём объекты окон на сонове оконных типов данных из загруженных сборок*/
DrawerWindow = Activator.CreateInstance(DrawerAsm.GetType("TextDrawer.Form1")) as Form;
TextWindowWnd = Activator.CreateInstance(
TextWindowAsm.GetType("TextWindow.Form1"),
new object[]
{
DrawerAsm.GetModule("TextDrawer.exe"),
DrawerWindow
}) as Form;
/*запускаем потоки*/
(new Thread(new ThreadStart(RunVisualizer))).Start();
(new Thread(new ThreadStart(RunDrawer))).Start();
/*добавляем обработчик события DomainUnload*/
Drawer.DomainUnload += new EventHandler(Drawer_DomainUnload);
}
示例2: DynamicAssemblyProxy
public DynamicAssemblyProxy(string luceneIndexFolder)
{
_currentDomain = AppDomain.CurrentDomain;
const string asemblyName = "dynamicProcessLib";
const string systemAsemblyName = "dynamicProcessLibSys";
//const string asemblyName = "dynamicProcessLib, Version=1.1.166.5, Culture=neutral, PublicKeyToken=null";
//const string systemAsemblyName = "dynamicProcessLibSys, Version=1.1.166.5, Culture=neutral, PublicKeyToken=null";
try
{
systemAssembly = _currentDomain.Load(systemAsemblyName);
userAssembly = _currentDomain.Load(asemblyName);
}
catch (Exception ex)
{
throw new ApplicationException(
string.Format(CultureInfo.InvariantCulture,
"Global Search Exception : AppDomain/ problem on loading (AssemblyName : {1}) /{0}/",
luceneIndexFolder,
asemblyName),
ex);
}
_luceneIndexFolder = luceneIndexFolder;
InitializeService();
}
示例3: DomTester
/// <summary>
/// Initializes a new instance of the NamespaceDeclaration class.
/// </summary>
/// <param name="nsdecl">The namespace being compiled.</param>
public DomTester(NamespaceDeclaration nsdecl)
{
_nsdecl = nsdecl;
_appDomain = AppDomain.CreateDomain("testdomain");
this.Compile();
_appDomain.Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
_appDomain.Load(_compiled.GetName());
}
示例4: 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;
}
}
示例5: RegisterWithBuilderFromPath
public static void RegisterWithBuilderFromPath(ContainerBuilder builder, AppDomain currentDomain, EnumRegistrationType enumRegistrationType)
{
List<Assembly> vuelingAssembliesList = new List<Assembly>();
Assembly[] vuelingAssembliesArray;
customRegistration(builder);
List<Assembly> assemblies = currentDomain.GetAssemblies().ToList<Assembly>();
var loadedAssemblies = currentDomain.GetAssemblies().ToList();
var loadedPaths = loadedAssemblies.Select(a => a.Location).ToArray();
var referencedPaths = Directory.GetFiles(currentDomain.BaseDirectory, "*.dll");
var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList();
toLoad.ForEach(path => loadedAssemblies.Add(currentDomain.Load(AssemblyName.GetAssemblyName(path))));
foreach (var referencedAssembly in toLoad)
{
assemblies.Add(Assembly.LoadFrom(referencedAssembly));
}
foreach (var assembly in assemblies.Distinct())
{
if (assembly.GetName().Name.ToLower().Contains("vueling")) vuelingAssembliesList.Add(Assembly.Load(assembly.GetName().Name));
}
vuelingAssembliesArray = vuelingAssembliesList.ToArray<Assembly>();
if (enumRegistrationType == EnumRegistrationType.justWithDecoratedClasses) RegisterAssemblyTypesWithDecoratedClasses(builder, vuelingAssembliesArray);
else RegisterAssemblyTypes(builder, vuelingAssembliesArray);
}
示例6: 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);
}
示例7: LoadAssembly
private static void LoadAssembly(AppDomain newAppDomain, string assemblyName)
{
try
{
newAppDomain.Load(assemblyName);
}
catch (FileNotFoundException ex)
{
Console.WriteLine(ex.Message);
}
}
示例8: Init
public void Init()
{
AppDomainSetup testDomainSetup = new AppDomainSetup()
{
ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase
};
_TestDomain = AppDomain.CreateDomain("SampleServiceDomain",
null,
testDomainSetup);
_TestDomain.Load("SampleService");
}
示例9: Init
public void Init()
{
_EmptyDomain = AppDomain.CreateDomain("EmptyDomain");
//_EmptyDomain = AppDomain.CurrentDomain;
//this doesn't seem to work as expected - if this is run concurrently with the EmptyResourceList test using CurrentDomain, things break
AppDomainSetup testDomainSetup = new AppDomainSetup();
testDomainSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
_TestDomain = AppDomain.CreateDomain("SampleServiceDomain",
null,
testDomainSetup);
_TestDomain.Load("SampleService");
}
示例10: LoadAssembliesForVersion
private void LoadAssembliesForVersion()
{
_appDomain = AppDomain.CreateDomain("NHibernateContext");
var nhibernatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format(@"DataContext\{0}", _version));
var assembliesToLoad = Directory.GetFiles(nhibernatePath, "*.dll");
foreach (var assemblyFile in assembliesToLoad)
{
var assemblyFileName = new FileInfo(assemblyFile).Name;
var assemblyFileToCreate = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assemblyFileName);
File.Copy(assemblyFile, assemblyFileToCreate, true);
_appDomain.Load(AssemblyName.GetAssemblyName(assemblyFileToCreate));
}
}
示例11: CreateAppdomain
public void CreateAppdomain()
{
var appdomainSetup = new AppDomainSetup();
//string appBase = Environment.CurrentDirectory;
//string appBase = HttpContext.Current.Request.ApplicationPath;
appdomainSetup.ApplicationBase = CodeTemplateProjectInfo.BLASSEMBLYLOCATIONPATHONLY;
//System.Diagnostics.Debug.WriteLine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase);
appdomainSetup.DisallowBindingRedirects = false;
appdomainSetup.DisallowCodeDownload = true;
appdomainSetup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
appDomain = AppDomain.CreateDomain("compilerAppdomain", null, appdomainSetup);
appDomain.Load(AssemblyName.GetAssemblyName(CodeTemplateProjectInfo.BLASSEMBLYLOCATION));
}
示例12: Launch
public void Launch(string pluginPath, AppDomain appDomain, Uri pluginApiUri, int clientPort, string tokenValue)
{
var token = Token.With(tokenValue);
var assembly = appDomain.Load(AssemblyName.GetAssemblyName(pluginPath));
var pluginDirectory = Path.GetDirectoryName(pluginPath);
appDomain.AssemblyResolve += (sender, args) =>
{
var ad = sender as AppDomain;
var path = Path.Combine(pluginDirectory, args.Name.Split(',')[0] + ".dll");
return ad.Load(path);
};
var pluginBootstrapperType = assembly.GetTypes().Single(t => typeof (IPluginBootstrapper).IsAssignableFrom(t));
var pluginBootstrapper = (IPluginBootstrapper) Activator.CreateInstance(pluginBootstrapperType);
var uri = new Uri($"http://127.0.0.1:{clientPort}");
var pluginRegistration = new PluginRegistration(
uri,
token,
new CommandApi(pluginApiUri, token),
new MessageApi(pluginApiUri, token),
new HttpApi(),
new Apis.PluginApi(pluginApiUri, token),
new ConfigApi(pluginApiUri, token),
new SettingApi(pluginApiUri, token));
pluginBootstrapper.Start(r =>
{
r(pluginRegistration);
if (pluginRegistration.PluginInformation == null)
{
throw new InvalidOperationException("You must call SetPluginInformation(...)");
}
using (var a = AsyncHelper.Wait)
{
a.Run(pluginRegistration.CommandApi.RegisterAsync(
pluginRegistration.CommandDescriptions,
CancellationToken.None));
}
});
_apiHost = new ApiHost();
_apiHost.Start(uri, pluginRegistration);
}
示例13: StartServers
public static void StartServers(TestContext ctx)
{
#region TCP Duplex
// Setup TCP Duplex Server AppDomain
AppDomainSetup tcpDuplexAppDomainSetup = new AppDomainSetup() { ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) };
_tcpDuplexServerAppDomain = AppDomain.CreateDomain("RecreateClientConnectionTests_Server", null, tcpDuplexAppDomainSetup);
_tcpDuplexServerAppDomain.Load(typeof(ZyanConnection).Assembly.GetName());
// Start Zyan host inside the TCP Duplex Server AppDomain
var tcpDuplexServerWork = new CrossAppDomainDelegate(() =>
{
var server = TcpDuplexServerHostEnvironment.Instance;
if (server != null)
{
Console.WriteLine("TCP Duplex Server running.");
}
});
_tcpDuplexServerAppDomain.DoCallBack(tcpDuplexServerWork);
#endregion
#region TCP Simplex
// Setup TCP Simplex Server AppDomain
AppDomainSetup tcpSimplexAppDomainSetup = new AppDomainSetup() { ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) };
_tcpSimplexServerAppDomain = AppDomain.CreateDomain("RecreateClientConnectionTests_Server", null, tcpSimplexAppDomainSetup);
_tcpSimplexServerAppDomain.Load(typeof(ZyanConnection).Assembly.GetName());
// Start Zyan host inside the TCP Simplex Server AppDomain
var tcpSimplexServerWork = new CrossAppDomainDelegate(() =>
{
var server = TcpSimplexServerHostEnvironment.Instance;
if (server != null)
{
Console.WriteLine("TCP Simplex Server running.");
}
});
_tcpSimplexServerAppDomain.DoCallBack(tcpSimplexServerWork);
#endregion
}
示例14: CreateReflectionAssembly
public static SR.Assembly CreateReflectionAssembly (AssemblyDefinition asm, AppDomain domain)
{
using (MemoryBinaryWriter writer = new MemoryBinaryWriter ()) {
WriteAssembly (asm, writer);
return domain.Load (writer.ToArray ());
}
}
示例15: Main
public static int Main(string[] args)
{
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
_serverAppDomain = AppDomain.CreateDomain("Server", null, setup);
_serverAppDomain.Load(typeof(ZyanConnection).Assembly.GetName());
CrossAppDomainDelegate serverWork = new CrossAppDomainDelegate(() =>
{
var server = EventServer.Instance;
if (server != null)
{
Console.WriteLine("Event server started.");
}
});
_serverAppDomain.DoCallBack(serverWork);
// Test IPC Binary
int ipcBinaryTestResult = IpcBinaryTest.RunTest();
Console.WriteLine("Passed: {0}", ipcBinaryTestResult == 0);
// Test TCP Binary
int tcpBinaryTestResult = TcpBinaryTest.RunTest();
Console.WriteLine("Passed: {0}", tcpBinaryTestResult == 0);
// Test TCP Custom
int tcpCustomTestResult = TcpCustomTest.RunTest();
Console.WriteLine("Passed: {0}", tcpCustomTestResult == 0);
// Test TCP Duplex
int tcpDuplexTestResult = TcpDuplexTest.RunTest();
Console.WriteLine("Passed: {0}", tcpDuplexTestResult == 0);
// Test HTTP Custom
int httpCustomTestResult = HttpCustomTest.RunTest();
Console.WriteLine("Passed: {0}", httpCustomTestResult == 0);
// Test NULL Channel
const string nullChannelResultSlot = "NullChannelResult";
_serverAppDomain.DoCallBack(new CrossAppDomainDelegate(() =>
{
int result = NullChannelTest.RunTest();
AppDomain.CurrentDomain.SetData(nullChannelResultSlot, result);
}));
var nullChannelTestResult = Convert.ToInt32(_serverAppDomain.GetData(nullChannelResultSlot));
Console.WriteLine("Passed: {0}", nullChannelTestResult == 0);
// Stop the event server
EventServerLocator locator = _serverAppDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, "IntegrationTest_DistributedEvents.EventServerLocator") as EventServerLocator;
locator.GetEventServer().Dispose();
Console.WriteLine("Event server stopped.");
if (!MonoCheck.IsRunningOnMono || MonoCheck.IsUnixOS)
{
// Mono/Windows bug:
// AppDomain.Unload freezes in Mono under Windows if tests for
// System.Runtime.Remoting.Channels.Tcp.TcpChannel were executed.
AppDomain.Unload(_serverAppDomain);
Console.WriteLine("Server AppDomain unloaded.");
}
if (ipcBinaryTestResult + tcpBinaryTestResult + tcpCustomTestResult + tcpDuplexTestResult + httpCustomTestResult + nullChannelTestResult == 0)
{
Console.WriteLine("All tests passed.");
return 0;
}
return 1;
}