appdomain

How to change permissions of AppDomain?

北城以北 提交于 2019-12-06 11:47:17
问题 I use special method to create sandobx: internal static class Helper { public static AppDomain CreateSandbox() { Contract.Ensures(Contract.Result<AppDomain>() != null); var platform = Assembly.GetExecutingAssembly(); var name = platform.FullName + ": Sandbox " + Guid.NewGuid(); var setup = new AppDomainSetup { ApplicationBase = platform.Location }; var permissions = new PermissionSet(PermissionState.None); permissions.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read |

Is it possible to have one Exception handler for multiple timers in a C# class?

我只是一个虾纸丫 提交于 2019-12-06 11:45:55
I have a C# program which runs a system tray application - transferring / moving / creating / editing files in the background. There is alot of exception handling and loop handling to prevent the program from crashing / getting stuck if the user manual deletes a file the program is working with. Unfortunately one of the computer the program is running on is having the program crash. The computer is very hard to get, and cannot have debugging software loaded on (it is an embedded PC outside with no network access). I have tried finding the cause of the crash (such as an unhandled exeption)

Using the LoaderOptimizationAttribute on a WCF service

徘徊边缘 提交于 2019-12-06 11:08:27
I have a wcf service that uses the .net System.AddIns framework to load assemblies into a seperate process and app domain. To improve performance I want to enable the Cross-Domain FastPath. According to the documentation I need to add the LoaderOptimizationAttribute attribute to the main method of my host application. However I do not have a main method as I am using a service. So is it possible to use the attribute? If not then how can I ensure that the addin assemblies are loaded as domain neutral? Thanks. If you are hosting in IIS, you should be gettng "LoaderOptimization(LoaderOptimization

Dynamically Loaded Assembly - Settings & Communication

筅森魡賤 提交于 2019-12-06 10:43:14
问题 Ok so... I have a WPF application (let's call it Launcher.exe ) which loads and executes another WPF application (let's call it Loaded.exe ) dynamically using something like this: Byte[] assemblyData; using (BinaryReader reader = new BinaryReader(new FileStream(filePath, FileMode.Open))) assemblyData = reader.ReadBytes(Convert.ToInt32(fs.Length)); Assembly assembly = Assembly.Load(assemblyData); MethodInfo method = assembly.EntryPoint; if (method != null) { Object instance = assembly

How to get parent AppDomain?

余生长醉 提交于 2019-12-06 08:35:35
问题 I need to do something like this in c# (pseudo): static var ns = new Non_Serializable_Nor_Marshal() var app = new AppDomain(); app.execute(foo) void foo() { var host = AppDomain.Current.Parent; //e.g. the original one host.execute(bar) } void bar() { ns.Something(); } IOW I have a non serializeable nor marshal object in one appdomain. I want to create a second domain and execute foo(). From within that second domain I want to execute bar() on the original domain. How do I pass the original

Executing and then Deleting a DLL in c#

别等时光非礼了梦想. 提交于 2019-12-06 05:22:06
I'm creating a self updating app where I have the majority of the code in a seperate DLL. It's command line and will eventually be run on Mono. I'm just trying to get this code to work in C# on windows at the command line. How can I create a c# application that I can delete a supporting dll while its running? AppDomain domain = AppDomain.CreateDomain("MyDomain"); ObjectHandle instance = domain.CreateInstance( "VersionUpdater.Core", "VersionUpdater.Core.VersionInfo"); object unwrap = instance.Unwrap(); Console.WriteLine(((ICommand)unwrap).Run()); AppDomain.Unload(domain); Console.ReadLine(); at

Create .NET 2.0 AppDomain in .NET 4.0 process

一曲冷凌霜 提交于 2019-12-06 04:29:15
I need to dynamically create a .NET 2.0 compatible assembly from within my .NET 4.0 process. Currently it is achieved with this: AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly(...) ModuleBuilder mb = assemblyBuilder.DefineDynamicModule(...); But unfortuntely all dll's produced are .NET 4.0 (inherited from my 4.0 process) which doesn't work with my other .NET 2.0 processes. Any idea how 2 different CLR versioned AppDomains can co-exist in the same process? Have a look at this question: http://social.msdn.microsoft.com/Forums/en/clr/thread/1bfd7f40-fd57-4c9f-803f-aa4b19214af9

How to properly access the PrivateBinPath property of the current AppDomain?

一世执手 提交于 2019-12-06 01:16:38
问题 Since AppDomain.AppendPrivatePath() is obsolete, I'm trying to figure out how to specify a PrivateBinPath for the current AppDomain in my project without spinning up a whole new AppDomain, and being able to access it later. I know I can set the PrivateBinPath on an AppDomainSetup object (which would be ok if I wanted to create a new AppDomain), and I also know that I can add it to my app.config like so: <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath=

what happens when an object derives from MarshalByRefObject and is also marked [Serializable]?

北城以北 提交于 2019-12-05 22:19:05
I'm working on my first project that uses AppDomains and I'm wondering what happens when an object derives from MarshalByRefObject and is also marked [Serializable]? for example: [Serializable] public class DummyClass: MarshalByRefObject { } It gets marshalled by reference, but can still be serialised for other use-cases for serialisation. There's an implementation detail to this that is interesting enough to be worth noting: The formatter that is serialising for remoting uses a SurrogateSelector that will produce a proxy for any MarshalByRefObject it serialises, hence serialising will still

AppDomains vs. a robust server

醉酒当歌 提交于 2019-12-05 21:59:17
after doing some research it seems that AppDomains are not really a tool for building a hosting server. From my understanding, the hosting server will still crash if there is an unhandled exception in a created AppDomain (if the exception is thrown from a thread in the created AppDomain). So in that case if the hosting server hosts a service which leaks exceptions this will bring down the default AppDomain as well. So I guess from a server architecture point-of-view there is nothing better than creating child processes and monitoring them. Is that correct or am I missing something with