appdomain

How can I switch .NET assembly for execution of one method?

假如想象 提交于 2019-12-01 04:38:30
问题 I have different versions of dlls for my .NET application and most of the time I want to use the latest one. However, there is one method which I run on a separate thread where I need to be able to select an older version of the dll based on some criteria. I have learned that it is not possible to just load an assembly and then unload it within the default application domain (I can't just keep both versions loaded because then I'm running into duplicate definitions of types problem) Probably

How to use Castle.Windsor in an assembly loaded using reflection

让人想犯罪 __ 提交于 2019-12-01 00:56:40
Let's say I have a library Lib.dll, which uses Castle.Windsor to initialize its services. I have a main application App.exe, which loads Lib.dll on runtime using reflection. App.exe does not know the location of Lib.dll beforehand, it is only known at runtime. In this case, when App.exe loads Lib.dll and Lib.dll initialize its services, a System.TypeInitializationException exception is thrown, because Castle.Windsor cannot find the service type. Castle.MicroKernel.SubSystems.Conversion.ConverterException: Could not convert from 'Lib.TheServiceClass' to System.Type - Maybe type could not be

ASP.NET Data Cache - preserve contents after app domain restart

ぐ巨炮叔叔 提交于 2019-11-30 22:45:53
I am using ASP.NET's data caching API. For example: HttpRuntime.Cache.Insert(my_data, my_key); Is there any way to configure cache so its contents are preserved when the App Domain recycles? I load many object into cache, but there is a substantial delay re-loading these every time the app domain restarts. Assume for this question that I can't prevent the appdomain restart due to a server configuration. Is there any way to configure cache so its contents are preserved when the App Domain recycles? No. The Cache object holds references in RAM. Period. Alternatives: Out-of-process Session state

Load static class in appdomain

限于喜欢 提交于 2019-11-30 22:34:00
I'm met with a big problem in C# AppDomain. I need to load a static class in a .dll file and execute its method: When I try to load them by Assembly.LoadFrom("XXXXX") // (XXXXX is the full path of dll) the .dll will not be unload automatically or programmatically. When I try to load them in AppDomain like adapterDomain = AppDomain.CreateDomain("AdapterDomain"); (a)adapterDomain.CreateInstanceFrom(this.AdapterFilePath, this.AdapterFullName); (b)adapterAssembly=adapterDomain.Load(AssemblyName.GetAssemblyName(this.AdapterFilePath)); If I use method (a), because the target class is a static one,

Read the content of the string intern pool

风格不统一 提交于 2019-11-30 20:30:31
I would like to enumerate the strings that are in the string intern pool . That is to say, I want to get the list of all the instances s of string such that: string.IsInterned(s) != null Does anyone know if it's possible? Thanks to the advice of @HansPassant, I managed to get the list of string literals in an assembly. Which is extremely close to what I originally wanted. You need to use read assembly meta-data, and enumerate user-strings. This can be done with these three methods of IMetaDataImport : [ComImport, Guid("7DAC8207-D3AE-4C75-9B67-92801A497D44")] [InterfaceType(ComInterfaceType

How to use an AppDomain to limit a static class' scope for thread-safe use?

有些话、适合烂在心里 提交于 2019-11-30 20:15:08
I have been bitten by a poorly architected solution. It is not thread safe! I have several shared classes and members in the solution, and during development all was cool... BizTalk has sunk my battle ship. We are using a custom BizTalk Adapter to call my assemblies. The Adapter is calling my code and running things in parallel, so I assume it is using multiple threads all under the same AppDomain. What I would like to do is make my code run under its own AppDomain so the shared problems I have will not muck with each other. I have a very simple class that the BizTalk adapter is instantiating

Remoting sponsor stops being called

心已入冬 提交于 2019-11-30 19:45:01
问题 I've got an app which creates several AppDomains in a single process and communicates between them via remoting. I create sponsors for all objects to prevent them from being GCed. But, some ended up being GCed anyway. After some investigation I've determined that depending on the InitialLeaseTime set on my remote objects, my sponsors are either never called or get called a couple times and then never again. My sponsor (I've removed some sanity checking for brevity): class Sponsor :

AppDomain Unload killing Parent AppDomain

时光毁灭记忆、已成空白 提交于 2019-11-30 19:19:21
I am having trouble figuring something out about my AppDomain.Unload(...) call. I have a detailed explanation with code from my earlier question . As it turns out, I was performing a couple of steps that apparently, I don't need to. However, I am fairly certain that when an AppDomain is created and then held in a collection: private static Dictionary<string , AppDomain> HostDomains; void StartNewDomain(string domainName) { AppDomain domain = AppDomain.CreateDomain(domainName); HostDomains[domainName] = domain; } ...when you are done with it, you must unload it: if (HostDomains.ContainsKey

Passing values back and forth appdomains

China☆狼群 提交于 2019-11-30 18:52:54
I have the following code: public class AppDomainArgs : MarshalByRefObject { public string myString; } static AppDomainArgs ada = new AppDomainArgs() { myString = "abc" }; static void Main(string[] args) { AppDomain domain = AppDomain.CreateDomain("Domain666"); domain.DoCallBack(MyNewAppDomainMethod); Console.WriteLine(ada.myString); Console.ReadKey(); AppDomain.Unload(domain); } static void MyNewAppDomainMethod() { ada.myString = "working!"; } I thought make this would make my ada.myString have "working!" on the main appdomain, but it doesn't. I thought that by inhering from

Mixing MarshalByRefObject and Serializable

那年仲夏 提交于 2019-11-30 14:33:10
Various sources explain that When an object derives form MarshalByRefObject, an object reference will be passed from one application domain to another rather than the object itself. When an object is marked with [Serializable], the object will be automatically serialized, transported from one application domain to another and then deserialized to produce an exact copy of the object in the second application domain. Note then that while MarshalByRefObject passes a reference, [Serializable] causes the object to be copied. [source] I'm designing my first app that uses AppDomains and I'm wondering