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 ?

1

6 Answers

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 
1

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.

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:

  • Open Visual Studio -> Help -> About Microsoft Visual Studio
  • Be sure these are installed:
    • Azure Functions and Web Jobs Tools (I have version: 16.5.236.49856)
      • Install instructions here:
    • Microsoft Azure Tools (I have version: 2.9)
      • Search for installer or here's a link to 2.9:

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

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

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

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

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like