sdk: Web Application build error with net6.0 framework, Failed to sign apphost with error code 0

Web Application build error with net6.0 framework.

I am working on MAC and dotnet core 3.1, 5.0 and 6.0 versions are installed on my machine. I not able to build Web Application on my machine due to shared error in this ticket.

I can build web application in target framework net5.0 but not with net6.0 and console, class library projects’ build successfully. I tried to build using command line, VS 2022/2019 but no success.

Project file code as below and this is empty Web API project.

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.5" />
  </ItemGroup>

</Project>

To Reproduce

Exceptions (if any)

/usr/local/share/dotnet/sdk/6.0.100-rc.2.21505.57/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(5,5): Error NETSDK1177: Failed to sign apphost with error code 0: /Users/ajandersingh/Projects/WebAppTest/WebAppTest/obj/Debug/net6.0/apphost: is already signed (NETSDK1177) (WebAppTest)

Further technical details

image

  • Include the output of dotnet --info
  • VS 2022 Preview and VS 2019

Please assist to resolve code build error. I apologies if I have posted issue is not relevant to reported category

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 3
  • Comments: 33 (10 by maintainers)

Most upvoted comments

sudo xcode-select -r fixing the issue for me…

I had this problem today, where it failed to sign apphost since it is already signed. It resolved itself and disappeared once I had installed the latest .Net SDK (6.0.202).

I started by trying out the other suggestions, with xcode etc, but this fixed in the end.

Captured a binlog, but it doesn’t show anything other than CreateAppHost being called, with the code signing flag passed through correctly.

With _EnableMacOSCodeSign set false: image

Without _EnableMacOSCodeSign set false: image

Nothing surprising there.

Digging into the implementation of CreateAppHost, I see it tries to remove the existing signature before sending it on to be signed:

// Remove the signature from MachO hosts.
if (!appHostIsPEImage)
{
    MachOUtils.RemoveSignature(fileStream);
} 

That method returns a boolean success/fail code, but it isn’t checked here and I don’t see any debug logging. Its implementation is here, and appears to have several places where it could exit early if it didn’t detect the type of signature it is expecting. My guess is that something changed with this last macOS 12.3.1 update that makes that code fail on x64-built files (or perhaps just x64-built files when running the code from an arm64 machine under Rosetta?)

Some other clues I just noticed from the signature in my previous post, the Format=Mach-O thin (x86_64) as well as the Identifier starting with func- not apphost-.

Here is my recollection of the time line for my experience with this issue. Hope this helps.

Time Line

  1. Before 04/01/22: Experimented with various WebJob telemetry settings
    • ran debug builds in VS Code, command line, everything was fine
  2. 04/01/22: Applied an MacOS update
  3. 04/02/22: Went back to working on the WebJob experiments
    • first build failed with the warning about an existing signature for my WebJob project
  4. Finally found this link .Net 6 AppHost Breaking Changes
  5. Set the UseAppHost to false in the csproj property group
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <UseAppHost>false</UseAppHost>
  </PropertyGroup>
  1. Local builds (VS Code debug and command line) work fine now.

Questions for the MS Folks:

  1. What are the side effects of setting the UseAppHost to false?
  2. Is there a way to address the problem of conflicting app signatures without UseAppHost?