Azure / azure-webjobs-sdk

Azure WebJobs SDK
MIT License
739 stars 358 forks source link

Cannot build functions with .NET 6 on macOS #2755

Open johnkors opened 3 years ago

johnkors commented 3 years ago

Hi,

I'm getting this fatal error at build time when using the .NET 6 previews:

error : Metadata generation failed. Exit code: '137' Error: 'Failed to initialize CoreCLR, HRESULT: 0x80004005'

/Users/johnkors/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/1.2.0/build/Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(37,5): warning : Failed to initialize CoreCLR, HRESULT: 0x80004005 [/Users/johnkors/kode/blank/fplbot-org/fplbot/src/FplBot.Functions/FplBot.Functions.csproj]
/Users/johnkors/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/1.2.0/build/Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(37,5): error : Metadata generation failed. Exit code: '137' Error: 'Failed to initialize CoreCLR, HRESULT: 0x80004005' [/Users/johnkors/kode/blank/fplbot-org/fplbot/src/FplBot.Functions/FplBot.Functions.csproj]

Not sure if it's on your end or the .NET SDK team..?

OS: macOS .NET SDK : .NET 6 Preview 7 ( 6.0.100-preview.7.21379.14 ) TFM: netcoreapp3.1 Microsoft.NET.Sdk.Functions Version 3.0.13

csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
  </ItemGroup>
...
$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.100-preview.7.21379.14
 Commit:    22d70b47bc

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.5
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.100-preview.7.21379.14/

Host (useful for support):
  Version: 6.0.0-preview.7.21377.19
  Commit:  91ba01788d

.NET SDKs installed:
  2.1.806 [/usr/local/share/dotnet/sdk]
  3.1.103 [/usr/local/share/dotnet/sdk]
  3.1.300 [/usr/local/share/dotnet/sdk]
  5.0.100 [/usr/local/share/dotnet/sdk]
  5.0.102 [/usr/local/share/dotnet/sdk]
  5.0.200 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.5.21302.13 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.6.21355.2 [/usr/local/share/dotnet/sdk]
  6.0.100-preview.7.21379.14 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.18 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.18 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0-rc.2.20475.17 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.5.21301.17 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.6.21355.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-preview.7.21378.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.18 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-preview.7.21377.19 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
v-anvari commented 3 years ago

Hi @johnkors , Thank you for reaching out to us, We will investigate this further and update you with the findings.

v-anvari commented 3 years ago

Kindly give us the repro steps and details of local deployment, so that we can reproduce this at our end

johnkors commented 3 years ago

Hm, not sure what more you need. The function csproj does not build, and provides the output shown above. So I guess: repo step: dotnet build a function project as shown here.

v-anvari commented 3 years ago

Hi @johnkors , We require the steps are language you are following to build.

garoyeri commented 3 years ago

I am having the same issue with the latest .NET 6 preview SDK installed: (Azure CLI and Azure Function Core Tools are installed)

mkdir api
cd api
dotnet new sln
func init StaticClingApi --worker-runtime dotnet
dotnet sln add StaticClingApi
cd StaticClingApi
func new --name SayHello --template "HTTP trigger" --authlevel "anonymous"
dotnet build

The failure is exactly what was mentioned earlier by @johnkors

johnkors commented 3 years ago

Hi @johnkors , We require the steps are language you are following to build.

Sorry, I thought it was evident that this was a .NET project from the details provided (.NET SDK, csproj, dotnet SDK, etc).

Language: C#, .NET

garoyeri commented 3 years ago

This might belong with https://github.com/Azure/azure-functions-host/tree/dev/tools/ExtensionsMetadataGenerator instead.

johnkors commented 3 years ago

Never got it working. To get back to a stable working environment, I had to

  1. Uninstall / remove all folders related to the .NET 6 SDK, https://docs.microsoft.com/en-us/dotnet/core/install/remove-runtime-sdk-versions?pivots=os-macos#uninstall-net
  2. Re-install the .NET 5 SDK

Then it builds fine.

garoyeri commented 3 years ago

The key was replacing the dotnet executable. I deleted it and reinstalled .NET 5 SDK to make it work again.

v-anvari commented 3 years ago

Discussed this issue internally and Tagging @mathewc / @brettsam for further investigation on .Net 6 SDK

garoyeri commented 3 years ago

I tried this on Windows and it works with the .NET 6 Preview SDK installed, seems like an issue primarily on MacOS.

johnkors commented 3 years ago

Mark, even if one uses a global.json specifycing the .NET 5 SDK to be used for builds, the build fails. Just having .NET 6 installed on macOS gives the error mentioned.

Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(37, 5): Metadata generation failed. Exit code: '137' Error: 'Failed to initialize CoreCLR, HRESULT: 0x80004005'

johnkors commented 3 years ago

I tried this on Windows and it works with the .NET 6 Preview SDK installed, seems like an issue primarily on MacOS.

Not sure, I tried macOS-11, windows-latest and ubuntu-latest on GH actions: https://github.com/johnkors/dotnet6-sdk-w-functions/actions/runs/1216552699

They all build fine.

Perhaps it's something in the .NET 6 installer for macOS, then? I downloaded it directly from the web instead of using say homebrew. How about you @garoyeri ?

I think it has to be, since the issue does not go away until I re-install the .NET 5 after uninstalling .NET 6.

johnkors commented 3 years ago

I tried the installing the .NET 6 RC2 installer from here, and did not have the same issues.

image

garoyeri commented 3 years ago

I just upgraded to the rc1:

.NET SDK (reflecting any global.json):
 Version:   6.0.100-rc.1.21458.32
 Commit:    d7c22323c4

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.100-rc.1.21458.32/

Host (useful for support):
  Version: 6.0.0-rc.1.21451.13
  Commit:  d7619cd4b1

.NET SDKs installed:
  3.1.412 [/usr/local/share/dotnet/sdk]
  5.0.203 [/usr/local/share/dotnet/sdk]
  5.0.302 [/usr/local/share/dotnet/sdk]
  5.0.400 [/usr/local/share/dotnet/sdk]
  6.0.100-rc.1.21458.32 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.18 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.1.21452.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.28 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.18 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.1.21451.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

When I run the build of a Azure Function project, it still fails with the same error message:

/Users/garo.yeriazarian/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/1.2.0/build/Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(37,5): error : Metadata generation failed. Exit code: '137' Error: 'Failed to initialize CoreCLR, HRESULT: 0x80004005' [/var/folders/dq/zp5p5h5s285gw2dpq8pwzwt80000gp/T/ffcamiik.4ee/WorkerExtensions.csproj]
fabiocav commented 3 years ago

Can you please upgrade your SDK version to https://www.nuget.org/packages/Microsoft.NET.Sdk.Functions/4.0.0-preview2 and let us know if the problem is resolved? Thanks!

/cc @brettsam

RichMercer commented 3 years ago

I've just tried this and I have the same issue. I should probably mention I wasn't previously using this SDK as I was referencing Microsoft.NET.Sdk.Functions.Worker.Sdk as I was using the isolated process with .NET 5.0. It still doesn't work with Core Tools v4 though.

johnkors commented 3 years ago

@fabiocav

Yep, that seems to work (i.e. I don't get the "error : Metadata generation failed. Exit code: '137' Error: 'Failed to initialize CoreCLR, HRESULT: 0x80004005'" error no more), except I get these build warnings instead:

dotnet6-sdk-w-functions git:(master) ✗ dotnet build SomeFunction
Microsoft (R) Build Engine version 17.0.0-preview-21458-01+2c5510013 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

/Users/johnkors/.nuget/packages/microsoft.net.sdk.functions/4.0.0-preview2/build/Microsoft.NET.Sdk.Functions.targets(74,5): warning : The ExtensionsMetadataGenerator package was not imported correctly. Are you missing '/Users/johnkors/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/4.0.0-preview1/build/Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets' or '/Users/johnkors/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/4.0.0-preview1/build/Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.props'? [/Users/johnkors/kode/temp/dotnet6-sdk-w-functions/SomeFunction/SomeFunction.csproj]

NB, notice the preview2 package tries to resolve props/targets from a preview1 package path.

johnkors commented 3 years ago

And a +1 on @RichMercer comment. The same issue of "Failed to initialize CoreCLR, HRESULT: 0x80004005'" applies to Microsoft.NET.Sdk.Functions.Worker.Sdk as well.

johnkors commented 3 years ago

Just to be double clear so you don't spend to much down the wrong rabbit hole: As i mentioned above, installing .NET 6 SDK RC2 last (meaning the sequence in which you install the .NET SDK matters for this issue) resolved this issue.

It builds both Microsoft.NET.Sdk.Functions.Worker.Sdk (dotnet-isolated) and Microsoft.NET.Sdk.Functions (in-process) projects just fine.

RichMercer commented 3 years ago

Just to be double clear so you don't spend to much down the wrong rabbit hole: As i mentioned above, installing .NET 6 SDK RC2 last (meaning the sequence in which you install the .NET SDK matters for this issue) resolved this issue.

I haven't been able to install the RC2 build as it fails so I cannot confirm. It seems there's a new build now than the screenshot above that doesn't work so I'll wait for a working build and try again.

RichMercer commented 3 years ago

I've managed to get RC2 installed and can confirm that I can now run dotnet-isolated on .NET 6.

garoyeri commented 3 years ago

Can you please upgrade your SDK version to https://www.nuget.org/packages/Microsoft.NET.Sdk.Functions/4.0.0-preview2 and let us know if the problem is resolved? Thanks!

/cc @brettsam

Question: where do I make this change in my csproj? I don't see a reference to this SDK anywhere in my project file.

johnkors commented 3 years ago

Question: where do I make this change in my csproj? I don't see a reference to this SDK anywhere in my project file.

Perhaps you created a dotnet-isolated function? Microsoft.NET.Sdk.Functions is for netcoreapp3.1 andin-process functions, and if you selected dotnet-isolated when running func init you'd get a reference to Microsoft.Azure.Functions.Worker.Sdk instead.

There does not seem to be an equivalent preview with a fix for Microsoft.Azure.Functions.Worker.Sdk (yet?), but as mentioned — it has the same issue.

image

RichMercer commented 3 years ago

.NET 6.0 RC2 also fixes the issues with Microsoft.Azure.Functions.Worker.Sdk as well, assuming you instal RC2 last. I confirmed this earlier today and have been happily running functions since. :)

misterjunio commented 3 years ago

I am facing the same issue. Project is on a Mac, with an isolated Azure function. Just tried today to upgrade to the newly minted .NET 6 stable version with Azure functions v4. Details below.

dotnet --info:

.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.6
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.100/

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  3.1.414 [/usr/local/share/dotnet/sdk]
  5.0.402 [/usr/local/share/dotnet/sdk]
  6.0.100 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.2.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.20 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.23 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.20 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

.csproj:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.0.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.0.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="4.0.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="4.0.1" />
    <PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
  </ItemGroup>

  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>

</Project>

Build error:

"/Users/junio.silva/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/4.0.1/build/Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(5,5): Error: Metadata generation failed. Exit code: '137' Error: 'Failed to initialize CoreCLR, HRESULT: 0x80004005' (SevenEleven.My7Eleven.Util.WakeUpMuleSoft)"

@RichMercer did you really manage to get it working with RC2? Cold you try with the stable version? Any pointers would be much appreciated.

johnkors commented 3 years ago

Yep, this is still an issue with RTM, not only previews / RCs. Updated to title of this ticket to reflect it. The only 2 possible resolutions I've found:

1) 🛠 Re-install .NET 5 SDK AFTER installing .NET 6. This will rollback the dotnet exec launcher to a .NET 5 version that works. Run this, to verify you use a 5.0 launcher:

➜ strings /usr/local/share/dotnet/dotnet | grep "@(#)" @(#)Version 5.0.1221.52207 @Commit: 7211aa01b34bb55ca67bdddd6e80ce23ee201bd2

2) 🔥 Remove all dotnet folders, SDKS and runtimes. Just burn it (sudo rm -rf /usr/local/share/dotnet/ ). Then install .NET 6 (NB! Only works 100% if you are on the latest Microsoft.Azure.Functions.* nugets, which it looks like you are)

brettsam commented 3 years ago

@misterjunio -- do you see this with a brand-new application? (one with fewer package refs?)

@fabiocav / @anthonychu -- could either of you take a look at this and see if you can repro it? Nothing is jumping out at me as to what the issue could be.

fabiocav commented 3 years ago

Haven't been able to repro, but seen reports that seem to point to possible issues with the .NET 6 installation, particularly on M1.

misterjunio commented 3 years ago

@brettsam just tried with a brand new project. Followed the steps here, essentially:

func init LocalFunctionProj --worker-runtime dotnet-isolated
cd LocalFunctionProj
func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"

then changed the target framework to 6.0:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <LangVersion>preview</LangVersion>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.12" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.0.1" OutputItemType="Analyzer" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.0.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Exact same error on build: "/Users/junio.silva/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/1.2.0/build/Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(5,5): Error: Metadata generation failed. Exit code: '137' Error: 'Failed to initialize CoreCLR, HRESULT: 0x80004005' (LocalFunctionProj)"

I assume this should be reproducible and not an issue with my environment.. @fabiocav FYI this is on an i7 (see my dotnet --info on comment above)

johnkors commented 3 years ago

It's actually not that easy to reproduce. I even tried with a macOS agent in a GitHub action with the exact same SDKs, and it built fine.

The only common denominator I found is with the sequence in which you install which SDK version matters (which I could not work out how to in a GitHub action).

The installer team looked at it here: https://github.com/dotnet/installer/issues/11951

Recommend reading what their take on it is.

I'm really unsure if this is with the functions SDK or with the installer in general, but finally just accepted it as a odd error with the 2 workarounds provided above.

brminnick commented 3 years ago

I can confirm that John's work-around, posted above, solved the Failed to initialize CoreCLR build error for me.

Thanks @johnkors!

Haven't been able to repro, but seen reports that seem to point to possible issues with the .NET 6 installation, particularly on M1

@fabiocav - I was experiencing this error on an Intel 2019 MacBook Pro.

liliankasem commented 3 years ago

Was having this issue trying to build the dotnet worker & host integration tests :D Workaround 1 from John worked for me - thanks for sharing. @fabiocav I believe it is an installation issue also

johnkors commented 2 years ago

@fabiocav

What about the DotNetMuxer? This code ExtensionsMetadataGenerator/DotNetMuxer.cs tries to do magic with the muxer with a bunch of fallbacks. Could there be a macOS + .NET 6 specific bug in that code? It has'nt been altered since 2018. Perhaps there are some behavioural changes for macOS + .NET 6 for the muxer?

rlvandaveer commented 2 years ago

I had this same issue on a Mac that had SDKs from 2 on installed. I was getting the same error against earlier versions of dotnet and Azure Function Core Tools. I uninstalled the 6 SDK using Homebrew i.e., brew uninstall dotnet-sdk. I then removed the contents of /usr/local/share/dotnet. (Unfortunately, I could not use Remove-Item as a few items needed different permissions and had to fall back to sudo rm -rf /usr/local/share/dotnet/.) I was then able to reinstall the 6 SDK via Homebrew brew install dotnet-sdk and version 4 of the Azure Function Core Tools and the issue now appears to be resolved. While this will allow me to create new functions, this will not allow me to maintain any functions still on the earlier SDKs.

johnkors commented 1 year ago

This is now an issue with .NET 8.

  1. The first workaround of re-installing an earlier version of the SDK does not work.
  2. The second workaround of uninstalling all previous SDKS, and then re-installing .NET 8 works.
jeffw-wherethebitsroam commented 11 months ago

So I've had this issue a few times and had it again today.

My environment:

% dotnet --info
.NET SDK:
 Version:           8.0.100
 Commit:            57efcf1350
 Workload version:  8.0.100-manifests.6c33ef20

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.6
 OS Platform: Darwin
 RID:         osx-x64
 Base Path:   /usr/local/share/dotnet/sdk/8.0.100/

.NET workloads installed:
 Workload version: 8.0.100-manifests.6c33ef20
There are no installed workloads to display.

Host:
  Version:      8.0.0
  Architecture: x64
  Commit:       5535e31a71

.NET SDKs installed:
  3.1.404 [/usr/local/share/dotnet/sdk]
  3.1.407 [/usr/local/share/dotnet/sdk]
  5.0.101 [/usr/local/share/dotnet/sdk]
  5.0.201 [/usr/local/share/dotnet/sdk]
  5.0.401 [/usr/local/share/dotnet/sdk]
  5.0.404 [/usr/local/share/dotnet/sdk]
  6.0.100 [/usr/local/share/dotnet/sdk]
  6.0.101 [/usr/local/share/dotnet/sdk]
  6.0.201 [/usr/local/share/dotnet/sdk]
  6.0.202 [/usr/local/share/dotnet/sdk]
  6.0.302 [/usr/local/share/dotnet/sdk]
  7.0.102 [/usr/local/share/dotnet/sdk]
  8.0.100 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.23 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.23 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.23 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

I created a new function app:

func init --worker-runtime dotnetIsolated --target-framework net6.0

And the build:

% dotnet build -bl
MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  fn-app-test -> /Users/jeffwilliams/dev/dotnet/fn-app-test/bin/Debug/net6.0/fn-app-test.dll
  Determining projects to restore...
  Restored /var/folders/jc/ctl0fvhs34v21m_hg1z3w0zh0000gp/T/2h2qmds1.x12/WorkerExtensions.csproj (in 950 ms).
  WorkerExtensions -> /var/folders/jc/ctl0fvhs34v21m_hg1z3w0zh0000gp/T/2h2qmds1.x12/buildout/Microsoft.Azure.Functions.Worker.Extensions.dll
/Users/jeffwilliams/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/4.0.1/build/Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(37,5): warning : Failed to initialize CoreCLR, HRESULT: 0x80004005 [/var/folders/jc/ctl0fvhs34v21m_hg1z3w0zh0000gp/T/2h2qmds1.x12/WorkerExtensions.csproj]
  Debug output from extension.json generator:

/Users/jeffwilliams/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/4.0.1/build/Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(37,5): error : Metadata generation failed. Exit code: '137' Error: 'Failed to initialize CoreCLR, HRESULT: 0x80004005' [/var/folders/jc/ctl0fvhs34v21m_hg1z3w0zh0000gp/T/2h2qmds1.x12/WorkerExtensions.csproj]

Build FAILED.

/Users/jeffwilliams/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/4.0.1/build/Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(37,5): warning : Failed to initialize CoreCLR, HRESULT: 0x80004005 [/var/folders/jc/ctl0fvhs34v21m_hg1z3w0zh0000gp/T/2h2qmds1.x12/WorkerExtensions.csproj]
/Users/jeffwilliams/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/4.0.1/build/Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(37,5): error : Metadata generation failed. Exit code: '137' Error: 'Failed to initialize CoreCLR, HRESULT: 0x80004005' [/var/folders/jc/ctl0fvhs34v21m_hg1z3w0zh0000gp/T/2h2qmds1.x12/WorkerExtensions.csproj]
    1 Warning(s)
    1 Error(s)

Looking at the binary log from the build, the failing step is:

image

And if I try that command:

% cd ~/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/4.0.1/tools/netstandard2.0/generator
% /usr/local/share/dotnet/dotnet Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.Console.dll "/var/folders/jc/ctl0fvhs34v21m_hg1z3w0zh0000gp/T/2h2qmds1.x12/buildout/bin" "/var/folders/jc/ctl0fvhs34v21m_hg1z3w0zh0000gp/T/2h2qmds1.x12/buildout/bin/extensions.json"
Failed to initialize CoreCLR, HRESULT: 0x80004005

So that is where the problem is happening. I've got no idea why Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.Console.dll causes that error.

jeffw-wherethebitsroam commented 11 months ago

I see that the linked issue from @rainersigwald also identifies this, but no short term fixes there.

jeffw-wherethebitsroam commented 11 months ago

So I ran a trace on this:

# In ~/.nuget/packages/microsoft.azure.webjobs.script.extensionsmetadatagenerator/4.0.1/tools/netstandard2.0/generator
% sudo dtruss dotnet Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.Console.dll &> ~/trace.txt

And in the trace I saw that it was using dotnet 2.1.23 (the oldest I have). Which seemed strange since I thought netstandard2.0 was supported by newer dotnet versions. So I removed dotnet 2.1.23 using:

% sudo dotnet-core-uninstall remove --runtime 2.1.23

Building again then succeed and building my original fn app project also succeeded (looks like it used 2.2.8).

So either my dotnet 2.1.23 runtime was broken somehow or it had a problem with Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.Console.dll. Either way, removing it worked.

I see most of the above dotnet --info lists contain a 2.1.* version. So I wonder if this applies to anyone else or just me?

Also, it seems strange that dotnet seems to prefer the oldest compatible version of the runtime when targeting netstandard2.0?