'Getting "Metadata generation failed" when building C# function app in Visual Studio 2019

Starting with a C# function app created as a new project in VS2019 (16.4.1) and latest Azure libraries (Azure Functions and Web Jobs Tools 16.4.457.38025) from VS Installer, it fails to build every time.

C:\Users\myname\.nuget\packages\microsoft.net.sdk.functions\1.0.29\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): error : Metadata generation failed.

Has anyone else been able to get this to work ?



Solution 1:[1]

To solve this issue, upgraded Microsoft.NET.Sdk.Functions to last version(3.0.1).And delete the netstandard1.0 folder:

"C:\Users\myname\.nuget\packages\microsoft.net.sdk.functions\1.0.29\build\netstandard1.0

Solution 2:[2]

This error started occurring for me when I upgraded the "Microsoft.NET.Sdk.Functions" to 4.0.0 or above (unfortunately). Staying with 3.0.13 allows it to compile without error.

Solution 3:[3]

In Visual Studio, when locally building .net core "azure functions" apps with Visual Studio, you get these errors post-build:

Severity    Code    Description Project File    Line    Suppression State
Error       Metadata generation failed. MyProject.Api   C:\Users\user\.nuget\packages\microsoft.net.sdk.functions\3.0.7\build\Microsoft.NET.Sdk.Functions.Build.targets 44  
Error       Stack overflow.     MyProject.Api   C:\Users\user\.nuget\packages\microsoft.net.sdk.functions\3.0.7\build\Microsoft.NET.Sdk.Functions.Build.targets 44  

This is a very frustrating reoccurring build error and the app will not run via the Functions CLI tools.

You may try:

  • Rebooting system, close/reopen Visual Studio
  • Manual steps of uninstall/reinstall .net frameworks or .net core
  • Uninstall/reinstall Visual Studio
    • It may work for a while, then regress
  • Completely reset Visual Studio
  • Manual steps of deleting local nuget SDK items
  • Upgrade your app's reference of "Microsoft.NET.Sdk.Functions" to the latest version
  • The list goes on and on of things you may try to fix it...

Note: This error does not happen in VS Code (for me), mainly because we run the explicit command: dotnet build

So what fixed it?

  • Uninstall all Visual Studio versions
  • Uninstall all old Visual Studio build tools/TFS or Build tools/plugins/extensions (Jetbrains products included)
  • Uninstall all .Net Core versions
  • Uninstall all old SDKs
  • Reviewing your installed "Programs and Features" list, be sure you uninstalled everything relating to SDKs, .Net Core, and Visual Studio.
  • Install Visual Studio 2019
    • During Visual Studio 2019 install, on individual components tab, be sure this is check (should be by default): individual components tab

After install completes:

In the freshly installed Visual Studio instance, open your Functions App, build it, and press F5 (the app runs via the AzureFunctionsTools cli_x64.exe process): cli_x64.exe process

Solution 4:[4]

What worked for me is:

  • be on your branch

  • git clean -xdf <-- this cleans the branch of all untracked files. So be careful and save and commit all your files first.

  • right click solution and clean

  • right click solution and rebuild

Solution 5:[5]

In my case I had 2 function Apps having the same Function name in the FucntionNameAttribute. By changing the names my Error get resolved

Solution 6:[6]

I have tried a lot of things. But you should have .Net Core 3.1 Runtime

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Joey Cai
Solution 2 TheTall
Solution 3
Solution 4 Thuy
Solution 5 Aziz Ahmed
Solution 6 Andrei Yaskevich