appdomain

Plugin AppDomains Workaround

时间秒杀一切 提交于 2019-12-05 19:21:05
When dealing with plugin assemblies in their own subdirectories, there is the well-known problem that these assemblies fail to load once they try to load their respective dependencies from their subdirectories. A solution is to load the plugins in AppDomains which had their PrivateBinPath set in their AppDomainSetup object upon initialization. However, this causes other difficulties concerning marshalling/cross-AppDomain communication, in particular if the plugins are supposed to provide some GUI. When security aspects have a lower priority (non-critical utility application, no severe problems

Restricted Permission AppDomain Grant Set Issue

a 夏天 提交于 2019-12-05 16:12:14
I have some code that dynamically compiles a Razor templates into an Assembly which I execute with a set of permissions (no access to files, etc). This works on our development computers and on our test server (Windows 2008 IIS7 x64 .NET 4). But on our production server (Same spec) it gives the error: "Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)" Here is the code: - public static SandboxContext Create(string pathToUntrusted, List<Assembly> references) { AppDomainSetup adSetup = new AppDomainSetup(); adSetup

IRegisteredObject not working as expected

杀马特。学长 韩版系。学妹 提交于 2019-12-05 07:00:34
问题 Background I'm working on an ASP.NET 4 web site (not web application). I'm trying to use IRegisteredObject to allow some long-running code to run in a non-request thread. For testing, I've set the IIS 7.5 application pool's recycle interval to low values so that it will try to recycle while the background thread is running. Code public class AspFriendlyBackgroundJob { private readonly object key = new object(); private readonly Task task; public AspFriendlyBackgroundJob(Action work) { lock

Can an appdomain be restricted to one directory?

老子叫甜甜 提交于 2019-12-05 06:49:50
I am developing a plugin host. The plugins should have as little trust as they need, however I want to have the possibility for a plugin to read and write files. Can the AppDomain where the assembly will be loaded be restricted to have access to only one directory for reading and writing? Other options and ways to go about this are also appreciated like for example easy ways to stream file data from the host to the plugin (reading) and from the plugin to the host (writing). If its relevant: I am using the MAF infrastructure for the plugins. http://msdn.microsoft.com/en-us/library/bb384200.aspx

How to gracefully unload a child AppDomain that has threads running

痞子三分冷 提交于 2019-12-05 05:47:56
I have a service that loads a child AppDomain and then starts a thread running in it. It needs an AppDomain because it dynamically generates and loads some code and I need to be able to restart it without killing the whole service. So there is a thread running in an event loop in the child AppDomain, it gets events passed to it through a MarshalByRefObject that sticks stuff in a concurrent queue. I want to stop and unload the child AppDomain and create a new one. I can simply call Unload on the child AppDomain, but that will abort all the threads and throw a ThrearAbortException. How can I

List all custom data stored in AppDomain

痞子三分冷 提交于 2019-12-05 03:01:27
In order to store the state of processes when an error occured, I would like to list all (custom) data stored in AppDomain (by SetData). The LocalStore property is private and AppDomain class not inheritable. Is there any way to enumerate those data ? AppDomain domain = AppDomain.CurrentDomain; domain.SetData("testKey", "testValue"); FieldInfo[] fieldInfoArr = domain.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance); foreach (FieldInfo fieldInfo in fieldInfoArr) { if (string.Compare(fieldInfo.Name, "_LocalStore", true) != 0) continue; Object value = fieldInfo.GetValue(domain)

Why Thread.CurrentContext property and Thread.GetDomain() method?

半腔热情 提交于 2019-12-05 01:11:42
问题 It's not a question of major importance, but I was wondering why the Thread class exposes a property for getting the current Context ( Thread.CurrentContext ) and a method for getting the current AppDomain ( Thread.GetDomain() ). Knowing the hierarchy of Process > AppDomain > Context > Thread, my assumption would be that the context for thread is known at current point in time, and the domain needs to be searched based on current context. But I'd like to hear wiser answers. Thanks! 回答1: my

How to pass a variable from one app domain to another

痞子三分冷 提交于 2019-12-04 23:10:01
I'd like to know, if I have a variable,for example, a string, how to pass its value to my new app domain: static string _str; static void Main(string[] args) { _str = "abc"; AppDomain domain = AppDomain.CreateDomain("Domain666"); domain.DoCallBack(MyNewAppDomainMethod); AppDomain.Unload(domain); Console.WriteLine("Finished"); Console.ReadKey(); } static void MyNewAppDomainMethod() { Console.WriteLine(_str); //want this to print "abc" } Thanks Oren Trutner Use one of the variations of AppDomain.CreateDomain that takes an AppDomainSetup argument. In the AppDomainSetup object, set the

Load and unload a dll dynamically into my project using AppDomain

落花浮王杯 提交于 2019-12-04 22:41:23
I want to use a class from a different project in a separate solution in my current project dynamically. I thought the solution is to load the dll into my project. I used the following code to do my task and it worked. string dllPath = @"the path of my dll"; var DLL = Assembly.LoadFile(dllPath); foreach (Type type in DLL.GetExportedTypes()) { if (type.Name == "targetClassName") { var c = Activator.CreateInstance(type); try { type.InvokeMember("myMethod", BindingFlags.InvokeMethod, null, c, new object[] { "Params" }); } catch(Exception ex) { MessageBox.Show(ex.Message); } break; } } However, my

Performance of the FrameworkElementAdapters class

送分小仙女□ 提交于 2019-12-04 18:17:39
Can't figure why cross-domain calls is so slow for FrameworkElementAdapters class. Here is a simple code: class Program { [STAThread] static void Main() { AppDomain domain = AppDomain.CreateDomain("AnotherDomain"); var instance = (AnotherDomainClass) domain.CreateInstanceAndUnwrap( typeof (AnotherDomainClass).Assembly.FullName, typeof (AnotherDomainClass).FullName); var contract = instance.CreateContract(); } } class AnotherDomainClass : MarshalByRefObject { public INativeHandleContract CreateContract() { return FrameworkElementAdapters.ViewToContractAdapter( new TextBlock()); } } The