We are providing an application as a self-contained dotnet core 3.1 single executable file. The exe is running as a service on various Windows Servers:
- Server 2012 64 bit
- Server 2016 64 bit
- Server 2019 64 bit
After some time of running (a week and above), the service fails to restart because of the missing AppName.deps.json file inside the temporary directory:
System.IO.FileNotFoundException: Could not find file 'C:\Windows\TEMP\.net\AppName\4rpjodow.e1g\AppName.deps.json'.
File name: 'C:\Windows\TEMP\.net\AppName\4rpjodow.e1g\AppName.deps.json'
at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.OpenRead(String path)
at Microsoft.Extensions.DependencyModel.FileWrapper.OpenRead(String path)
at Microsoft.Extensions.DependencyModel.DependencyContextLoader.LoadContext(IDependencyContextReader reader, String location)
at Microsoft.Extensions.DependencyModel.DependencyContextLoader.Load(Assembly assembly)
at Microsoft.Extensions.DependencyModel.DependencyContext.Load(Assembly assembly)
at Microsoft.Extensions.DependencyModel.DependencyContext.LoadDefault()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at System.Lazy`1.get_Value()
at Microsoft.Extensions.DependencyModel.DependencyContext.get_Default()
at Serilog.Settings.Configuration.Assemblies.AssemblyFinder.Auto()
at Serilog.ConfigurationLoggerConfigurationExtensions.Configuration(LoggerSettingsConfiguration settingConfiguration, IConfiguration configuration, String sectionName, DependencyContext dependencyContext)
at Serilog.ConfigurationLoggerConfigurationExtensions.Configuration(LoggerSettingsConfiguration settingConfiguration, IConfiguration configuration, DependencyContext dependencyContext)
at AppName.Program.<>c__DisplayClass2_0.<CreateWebHostBuilder>b__2(WebHostBuilderContext hostingContext, ILoggingBuilder logging)
at Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.<>c__DisplayClass9_1.<ConfigureLogging>b__1(ILoggingBuilder builder)
at Microsoft.Extensions.DependencyInjection.LoggingServiceCollectionExtensions.AddLogging(IServiceCollection services, Action`1 configure)
at Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions.<>c__DisplayClass9_0.<ConfigureLogging>b__0(WebHostBuilderContext context, IServiceCollection collection)
at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors)
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at AppName.Program.Main(String[] args)
By checking the directory we could see that there are missing some more .json and also .dll files. I guess that the file system cleanup removes all files that are not in use while the service is running.
Deleting the whole temp directory resolves the problem because the exe will be extracted again on startup. The problem seems to be the fact, that only some files get deleted and the content is not beeing extracted again.
Our preferred solution would be to extract the files to a directory outside the temp dir. Until now we did not found an option that would provide this feature. Also any other ideas to avoid deleting the temp files are welcome. We would like to keep on working with a single executable if possible because this makes shipping the application to our customers much more comfortable.
EDIT: This is the current PropertyGroup for publish from .csproj:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<Version>1.0-develop</Version>
<ApplicationVersion>1.0-develop</ApplicationVersion>
<Description>App-Description</Description>
<Copyright>Copyright © 2019 Company</Copyright>
<LangVersion>8</LangVersion>
<PublishTrimmed>true</PublishTrimmed>
<PublishSingleFile>true</PublishSingleFile>
<ApplicationIcon>Icon.ico</ApplicationIcon>
<AssemblyName>AppName</AssemblyName>
<RootNamespace>AppName</RootNamespace>
<PreserveCompilationContext>false</PreserveCompilationContext>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>