aspnetcore: Hosting multiple instances of an app published with PublishSingleFile and IncludeNativeLibrariesForSelfExtract does not work as expected.

Description

When compiling a web project to a single file application with IncludeNativeLibrariesForSelfExtract you can only run one instance of the application in IIS. If you try to run a second instance, it will try to extract from the same directory and fail to do so. This is contrary to the documented behavior I’ve read in one of dotnet’s design documents. Specifically the linked document says,

Check if the [extraction directory](Extraction Location) exists for this app: If not, perform a new extraction: Extract appropriate files to a temporary location <base>/<app>/<proc-id> . This ensures that concurrent launches of the app do not interfere with each other.

This isn’t the case in my experience.

If you remove the IncludeNativeLibrariesForSelfExtract option this problem goes away.

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
    <PublishSingleFile>true</PublishSingleFile>
    <SelfContained>true</SelfContained>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PublishReadyToRun>true</PublishReadyToRun>
    <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
  </PropertyGroup>

Reproduction Steps

  1. Open Visual Studio Version 16.10.3

  2. File -> New -> Project -> ASP NET Core Web App -> Next -> .Net 5.0 -> Create

  3. Paste this into the project file.

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
    <PublishSingleFile>true</PublishSingleFile>
    <SelfContained>true</SelfContained>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PublishReadyToRun>true</PublishReadyToRun>
    <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
  </PropertyGroup>
  1. Folder publish
  2. Copy to c:\inetpub\wwwroot\testproject1
  3. Copy to c:\inetpub\wwwroot\testproject2
  4. Convert each of these to web application in their own application pool
  5. Attempt to view each of these applications
  6. One will succeed and one will show a hosting error.
  7. Remove <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> from the project file.
  8. Republish to respective directories
  9. Both applications work

Expected behavior

The expected behavior is for both instances of the application to work properly when <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> is in the project file prior to publishing.

Actual behavior

The actual behavior is only a single instance working properly when <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> is included in the project file prior to publishing.

Regression?

I do not know if this worked in prior releases as this was my first attempt.

Known Workarounds

Removing <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> from the project file prior to publishing enables both applications to work but does NOT produce a single file build output.

Renaming one of the .exe files and it’s key in the associated web.config file allows this to work.

Configuration

Visual Studio: Microsoft Visual Studio Professional 2019 Version 16.10.3

OS: Edition Windows 10 Pro Version 21H1 Installed on ‎5/‎20/‎2021 OS build 19043.1237 Experience Windows Feature Experience Pack 120.2212.3530.0

Other information

No response

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 24 (15 by maintainers)

Most upvoted comments

@VSadov Any info?

@HaoK instead of Justin.