appdomain

How can I prevent CompileAssemblyFromSource from leaking memory?

岁酱吖の 提交于 2019-11-26 10:31:35
问题 I have some C# code which is using CSharpCodeProvider.CompileAssemblyFromSource to create an assembly in memory. After the assembly has been garbage collected, my application uses more memory than it did before creating the assembly. My code is in a ASP.NET web app, but I\'ve duplicated this problem in a WinForm. I\'m using System.GC.GetTotalMemory(true) and Red Gate ANTS Memory Profiler to measure the growth (about 600 bytes with the sample code). From the searching I\'ve done, it sounds

What is a .NET application domain?

我的梦境 提交于 2019-11-26 08:58:56
问题 In particular, what are the implications of running code in two different application domains? How is data normally passed across the application domain boundary? Is it the same as passing data across the process boundary? I\'m curious to know more about this abstraction and what it is useful for. EDIT: Good existing coverage of the AppDomain class in general at I don't understand Application Domains 回答1: An AppDomain basically provides an isolated region in which code runs inside of a

How to keep ASP.NET assemblies in AppDomain alive?

霸气de小男生 提交于 2019-11-26 08:58:37
问题 Scenario: I\'ve an n-Tier enterprise ASP.NET application deployed using Web Deployment Projects. All tiers produce independent assemblies that is consumed by the ASP.NET application. Problem: When I run the app. for the first time after deployment it takes lot of time to load dependent assemblies in memory. But once loaded its lighting fast app. In case if there are no users accessing the app, IIS unloads the assemblies from the memory and when a user tried to access the app on a later

Usage of AppDomain in C#

寵の児 提交于 2019-11-26 08:58:26
问题 What is the most important use of AppDomains in C#? 回答1: The single most important use is that your code has to have one - i.e. everything you write in C# executes in an AppDomain . That is quite important ;-p If you mean additional app-domains: When using plugins and other untrusted code, it allows you both isolation, and the ability to unload them (you can't unload assemblies - only entire app-domains). I'm using it currently to load dynamically generated dlls, so that I can unload them.

Static Fields in AppDomain

江枫思渺然 提交于 2019-11-26 08:12:53
问题 I\'m experimenting ideas around using AppDomain to manage some legacy code contains lots of static fields in a multi-threaded environment. I read answers this question: How to use an AppDomain to limit a static class\' scope for thread-safe use?, thought it\'s quite promising and decided to try it out with a very simple class in assembly ClassLibrary1.dll: namespace ClassLibrary1 { public static class Class1 { private static int Value = 0; public static void IncrementAndPrint() { Console

How to load a .NET assembly for reflection operations and subsequently unload it?

≡放荡痞女 提交于 2019-11-26 08:07:48
问题 I\'m writing a tool to report information about .NET applications deployed across environments and regions within my client\'s systems. I\'d like to read the values of assembly attributes in these assemblies. This can be achieved using Assembly.ReflectionOnlyLoad , however even this approach keeps the assembly loaded. The issue here is that I cannot load two assemblies that have the same name from different paths, so naturally I can\'t compare the same application deployed in different

Loading DLLs into a separate AppDomain

一曲冷凌霜 提交于 2019-11-26 05:56:23
问题 I want to load one or more DLLs dynamically so that they run with a different security or basepath than my main application. How do I load these DLLs into a separate AppDomain and instantiate objects from them? 回答1: More specifically AppDomain domain = AppDomain.CreateDomain("New domain name"); //Do other things to the domain like set the security policy string pathToDll = @"C:\myDll.dll"; //Full path to dll you want to load Type t = typeof(TypeIWantToLoad); TypeIWantToLoad myObject =

Loading multiple versions of the same assembly

那年仲夏 提交于 2019-11-26 04:50:38
问题 I\'m working with a third-party assembly and unfortunately I now need to load their latest and a previous version into my project so at runtime I can decide which one to load. I only ever need one, not both. With this in mind, I am also dependent upon the types provided by the components so I cannot load from reflection and query every time for the method/events/interfaces that I want to use. I have seen some mention of handling this via AppDomain s but am not sure how to proceed. Would the

How to unload an assembly from the primary AppDomain?

谁都会走 提交于 2019-11-26 04:47:20
问题 I would like to know how to unload an assembly that is loaded into the main AppDomain. I have the following code: var assembly = Assembly.LoadFrom( FilePathHere ); I need/want to be able to unload this assembly when I am done. Thanks for your help. 回答1: For .net versions core 3.0 and later: You can now unload assemblies. Note that appdomains are no longer available in .net core. Instead, you can create one or more AssemblyLoadContext, load your assemblies via that context, then unload that

How to Load an Assembly to AppDomain with all references recursively?

爷,独闯天下 提交于 2019-11-26 00:36:10
问题 I want to load to a new AppDomain some assembly which has a complex references tree (MyDll.dll -> Microsoft.Office.Interop.Excel.dll -> Microsoft.Vbe.Interop.dll -> Office.dll -> stdole.dll) As far as I understood, when an assembly is being loaded to AppDomain , its references would not be loaded automatically, and I have to load them manually. So when I do: string dir = @\"SomePath\"; // different from AppDomain.CurrentDomain.BaseDirectory string path = System.IO.Path.Combine(dir, \"MyDll