Migration from .net web application to .net core 3.1 RRS feed

  • Question

  • How to handle Appdomain in .net core , AppDomains were used for different purposes. For code isolation, we recommend processes and/or containers. For dynamic loading of assemblies, we recommend the new AssemblyLoadContext class.

    But the problem is when i am trying to add package system.runtime.loader which contain AssemblyLoadContext but it support only 4.6.2 framework but i am working on 4.8 framework. so what is other alternate package to handle AppDomains  in .net core 

    Rakesh Singh

    Monday, March 9, 2020 9:50 AM

All replies

  • please note i am migrating in .netcore 3.1

    Rakesh Singh

    Monday, March 9, 2020 9:51 AM
  • You should post to the Core forum in ASP.NET forums.


    Monday, March 9, 2020 10:21 AM
  • See the following page, search for App Domains then look at AssembyLoadContext class.

    Dependent on what you need some researching will be needed e.g.

       var basePath = AppContext.BaseDirectory;
       var basePath = AppDomain.CurrentDomain.BaseDirectory;

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    • Proposed as answer by CoolDadTx Monday, March 9, 2020 2:30 PM
    Monday, March 9, 2020 2:15 PM
  • As Karen points out, you'll have to use compile time directives to distinguish between AppDomains and AseemblyLoadContext. ALC is only supported in .NET Core so a .NET Framework app cannot use that functionality. AppDomain code is supported on .NET Core but you only get 1 AD in Core. So it depends upon what functionality you're calling as to what will and won't work. 

    If you're migrating from NF to NC then this shouldn't be an issue, just retarget to .NET Core (unfortunately not even .NET Standard works here) and then use ALC. If you want to do it piecemeal such that you can support both a NF and NC web app at the same time then you're going to have to introduce a level of indirection. It is interesting that there is no interop layer provided by MS here but you can easily write your own. Create an interface that provides the isolation you want using only types that are compatible with both frameworks. Then create separate assemblies (1 for NC and 1 for NF) that target the appropriate framework and implement your interface using AD or ALC as needed. Then at runtime load the appropriate assembly based upon the framework being used (aka Karen's code).

    Michael Taylor http://www.michaeltaylorp3.net

    Monday, March 9, 2020 2:30 PM
  • Hi 000sipi,
    As offical document said that AppDomains require runtime support and are generally quite expensive. While still implemented by CoreCLR, it’s not available in .NET Native and we don’t plan on adding this capability there.
    So it is not supported in .net Core 3.1. And AppDomains were used for different purposes. For code isolation, it is recommended to use processes and/or containers. For dynamic loading of assemblies,  it is recommended the new AssemblyLoadContext class.
    Here is related document you can refer to.
    [Replacing AppDomain in .Net Core]
    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
    Best Regards,
    Daniel Zhang

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 10, 2020 7:01 AM