azure-functions-core-tools icon indicating copy to clipboard operation
azure-functions-core-tools copied to clipboard

Dotnet 6.0 Azure function v4 build error - Visual Studio for Mac

Open toklive opened this issue 2 years ago • 31 comments

Build Error

/Users/user2/.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'
Done building target "_GenerateFunctionsExtensionsMetadataPostBuild" in project "testfunc.csproj" -- FAILED.

Done building project "testfunc.csproj" -- FAILED.

Build FAILED.

/Users/user2/.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
/Users/user2/.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'
   1 Warning(s)
   1 Error(s)
func version
4.0.3971
Visual Studio Enterprise 2022 for Mac Preview
Version 17.0 Preview (17.0 build 5186)

Azure function .csProj config

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

toklive avatar Dec 15 '21 22:12 toklive

Hi there, it seems a .NET 6 install breaks your Function app builds from what I can tell by reading this useful thread on it: https://issueexplorer.com/issue/dotnet/installer/11951. They're talking about reinstalling .NET 5. I also got this issue but was able to get around it another way by doing some clean up with my SDK and Runtimes currently installed.

I'd recommend downloading the .net uninstaller from here: https://github.com/dotnet/cli-lab/releases

Once it's running use the following command to see what you currently have installed, as a bonus it will also tell you which SDKs and runtimes are being used by Visual Studio - don't remove these. ./dotnet-core-uninstall list

I decided on what to remove by using dotnet sdk check and removed anything that said there's an update available (as long as that update was already in the list).

Then use the command line to delete your sdk --sdk or runtime --runtime e.g. sudo ./dotnet-core-uninstall remove 5.0.401 --sdk

Here's what my current SDK/Runtime setup in case you want to copy mine:

andrewbenson@Andrews-MacBook-Pro-2 ~ % dotnet sdk check
.NET SDKs:
Version      Status     
------------------------
3.1.416      Up to date.
5.0.404      Up to date.
6.0.101      Up to date.

.NET Runtimes:
Name                          Version      Status     
------------------------------------------------------
Microsoft.AspNetCore.App      3.1.22       Up to date.
Microsoft.NETCore.App         3.1.22       Up to date.
Microsoft.AspNetCore.App      5.0.13       Up to date.
Microsoft.NETCore.App         5.0.13       Up to date.
Microsoft.AspNetCore.App      6.0.1        Up to date.
Microsoft.NETCore.App         6.0.1        Up to date.

hope this helps

andrew-benson avatar Dec 16 '21 13:12 andrew-benson

Thank you I have cleaned and kept only 6.0, now i am getting other error and it seems related to https://github.com/Azure/azure-functions-core-tools/issues/2873

Azure Functions Core Tools
Core Tools Version:       3.0.3904 Commit hash: c345f7140a8f968c5dbc621f8a8374d8e3234206  (64-bit)
Function Runtime Version: 3.3.1.0

[2021-12-16T19:06:41.567Z] Found /Users/sowmyan/Projects/testfun2/testfun2/testfun2.csproj. Using for user secrets file configuration.
[2021-12-16T19:06:43.064Z] Cannot create directory for shared memory usage: /dev/shm/AzureFunctions
[2021-12-16T19:06:43.064Z] System.IO.FileSystem: Access to the path '/dev/shm/AzureFunctions' is denied. Operation not permitted.

VS 2022 for mac trying to load the function 3 instead of 4

dotnet sdk check                                   
.NET SDKs:
Version      Status     
------------------------
6.0.101      Up to date.

.NET Runtimes:
Name                          Version      Status     
------------------------------------------------------
Microsoft.AspNetCore.App      6.0.1        Up to date.
Microsoft.NETCore.App         6.0.1        Up to date.

toklive avatar Dec 16 '21 19:12 toklive

When I created my v4 function app, I did it from vscode using the Azure Functions extention. That seemed to install the necessary v4 core tool for me (that's what I got a glimpse of in the output window), perhaps give that a try then. Hope VS Code can help solve your issue: https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-csharp?tabs=in-process

andrew-benson avatar Dec 16 '21 23:12 andrew-benson

Thanks Andrew. Yes VS code works , issue is with VS 2022 for Mac

toklive avatar Dec 16 '21 23:12 toklive

@toklive Brill. However I haven't been able to get the debugger to attach in VSCode, so I'm unable to hit any breakpoints in my HttpTrigger function - I am using...

Azure Functions Core Tools
Core Tools Version:       4.0.3971 Commit hash: d0775d487c93ebd49e9c1166d5c3c01f3c76eaaf  (64-bit)
Function Runtime Version: 4.0.1.16815

Debugger attaches fine on a console app though so seems that it's just a problem for Function apps then. For now I'm not sure how to fix this issue but may open it up in a new ticket.

Edit: So I got it to work finally, not really sure what I did to get it to fix - closed vscode, cleaned project, started new function project from scratch and all of a sudden 'Attach to NET Funcions' worked.

andrew-benson avatar Dec 17 '21 09:12 andrew-benson

Thanks for the update @andrew-benson

toklive avatar Dec 17 '21 16:12 toklive

I was able to fix it with the uninstaller, but after a visual studio (for Mac) update it broke again. Uninstalling doesn't seem to do the trick anymore.

Reinstalling .NET 5 SDK does resolve the issue

johnnybegood avatar Feb 21 '22 10:02 johnnybegood

Thanks Johnny - reinstall fixed it for me too

samsutherland avatar Apr 02 '22 11:04 samsutherland

When I am trying to start my function app with this command "func start". It throws error "Failed to initialize CoreCL". This problem occurs when creating a new project with command line in Mac

developersamim avatar Apr 09 '22 12:04 developersamim

Reinstalling .Net SDK 5.0 does resolve the issue.

hanjiankang avatar May 30 '22 09:05 hanjiankang

Ok, upgraded .Net SDK 6 to latest, my V4 isolated function failed with above. Had to install latest .Net 5 SDK and then it started working again.

Hipster74 avatar Jun 09 '22 14:06 Hipster74

Same, had to reinstall 5.0.408 (latest) even if it was already installed

CerosDev avatar Jun 20 '22 18:06 CerosDev

Once I removed all the unnecessary runtimes and sdks as well as Microsoft.NETCore.App 2.1.23 .NET 2.1 is out of support. Mine started working EXCEPT I'm still not able to run a .NET 6 isolated Azure Function project locally - just build and publish Screen Shot 2022-07-18 at 7 02 34 PM .

GrumpyCockatiel avatar Jul 19 '22 00:07 GrumpyCockatiel

Thank you @andrew-benson your solution worked for me, I had the same error: JetBrains Rider and Azure Function, Mac Os 12.5

rafaelmtz avatar Aug 17 '22 19:08 rafaelmtz

I updated .net 6 SDK version 6.0.401, it working fine.

muhdammar avatar Sep 15 '22 15:09 muhdammar

macOS Monterey 12.6 dotnet sdk 6.0.401 azure-functions-core-tools@4 4.0.4785

Project is .Net 6.0 isolated process function

I am seeing this issue when building with the command line and with VS Code.

William-Froelich avatar Oct 05 '22 01:10 William-Froelich

Installing dotnet 5 also worked for me(to run a dotnet 6 isolated v4 azure function)

GBBBAS avatar Nov 07 '22 20:11 GBBBAS

Context & Problem I installed .NET 7.0 RC2 (.NET 7.0.100-rc.2.22477.23) recently. And I got this error, when building my Azure Functions project:

Error: Metadata generation failed. Exit code: '137'

Solution johnkors wrote (2021):

What I've found so far, is that after any install of .NET 6 preview/rc, I have to re-install .NET 5 to fix it. I don't really have to uninstall .NET 6 at all. As long as i run the .NET 5 installer after the .NET 6 installer, all is good.

Due to timing of .NET 7.0 just coming out, I didn't expect that reinstalling .NET 5.0 would help. But this worked:

  1. Install .NET 7.0 RC2
  2. Installed .NET 5.0

.NET 5.0 SDK (v5.0.408) - macOS x64 Installer! - GUI

Weird!

majew7 avatar Nov 07 '22 23:11 majew7

I wiped out my system and installed dotnet 7 and that seems to have resolved the build issue for me.

William-Froelich avatar Nov 14 '22 15:11 William-Froelich

Had same issue, reinstalling SDK v5 solved it.

M3talM0nk3y avatar Nov 27 '22 13:11 M3talM0nk3y