0

I am having a razor web app where few other razor web app are added dynamically using AssemblyLoadContext

Assembly assembly = _loadContext.LoadFromAssemblyPath(pluginLocation);

Since razor app assembly are added over run time it was required to add assembly to AddApplicationPart. _builder.AddApplicationPart(assembly);

After doing above steps I am able to browse through dynamically added razor web apps.

Issue occurred for when unloading the dynamically added assembly(razor web app).

Steps that I did to unload the assembly(razor web app) are

  • Removed CompiledRazorAssemblyPart and AssemblyPart from ApplicationPartManager
  • Unload AssemblyLoadContext using _loadContext.Unload()
  • Garbage collection using GC.Collect()

Even after doing the above steps dynamically loaded razor web app URL's/pages are accessible. Please suggest a solution to remove the assemblies.

DevCoder
  • 11
  • 1
  • Why do you want to remote the assemblies after you load it? – Xinran Shen Mar 15 '23 at 07:14
  • @XinranShen Each module of the application is created as separate Razor web app. So inorder to block the access to that module/feature I am plannig to unload the assemblies. I need to do this in runtime so that its not required to restart the Kestrel. – DevCoder Mar 15 '23 at 11:51
  • From MS Docs, To unload an assembly in the .NET Framework, you must unload all of the application domains that contain it. To unload an application domain, use the AppDomain.Unload method. For more information, see How to: [Unload an application domain](https://learn.microsoft.com/en-us/dotnet/framework/app-domains/how-to-unload-an-application-domain). Hope it can give you some help. – Xinran Shen Mar 16 '23 at 07:00
  • @XinranShen I am using .net core web app. In .net core Only 1 AppDomain is allowed. When try to create a new app domain or Unload exiting App domain it will throw error – DevCoder Mar 16 '23 at 12:51

0 Answers0