User-1262787652 posted
Debian /etc/systemd/system/kestrel-store.service contains
# https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-5.0
[Unit]
Description=My store5
[Service]
WorkingDirectory=/var/www/store5
ExecStart=/var/www/store5/Store
Restart=always
# Restart service after 5 seconds if the dotnet service crashes:
RestartSec=5
KillSignal=SIGINT
SyslogIdentifier=kestrel-store
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Development
#Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
It looks like service is re-started automatically.
Shold all threads aborted so that Linux will re-start service or is there better way, e.q unloading AppDomain ?
Which command should used to terminate all threads or unload appdomain in ASP.NET Core MVC controller ?
The following code is used used to replace assembly:
peStream = new MemoryStream();
bool enableLazyLoading = false;
var result = GenerateCode(sourceFiles, enableLazyLoading).Emit(peStream);
var assemblyLoadContext = new AssemblyLoadContext("DynamicContext", isCollectible: !enableLazyLoading);
peStream.Seek(0, SeekOrigin.Begin);
var fn = AppContext.BaseDirectory + "DynamicContext.dll";
File.Delete(fn);
File.WriteAllBytes(fn, peStream.ToArray());
peStream.Close();
When running from Visual Studio,
File.Delete(fn);
throws error
System.UnauthorizedAccessException
HResult=0x80070005
Message=Access to the path 'C:\MYApp\Store\bin\Debug\net5.0\DynammicContext.dll' is denied.
Source=System.IO.FileSystem
StackTrace:
at System.IO.FileSystem.DeleteFile(String fullPath)
at System.IO.File.Delete(String path)
..
How to make it working when application is running in development mode from Visual Studio ?
In Linux it replaces assembly properly.