Ed Bomke
Ed Bomke

Reputation: 91

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 ?

Upvotes: 9

Views: 39133

Answers (7)

You should check all the parameters of your functions. In my case the issue was related to the body parameter that was declared as dynamic.

Upvotes: 0

Andrei Yaskevich
Andrei Yaskevich

Reputation: 1

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

Upvotes: 0

Aziz Ahmed
Aziz Ahmed

Reputation: 11

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

Upvotes: 1

TheTall
TheTall

Reputation: 308

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.

Upvotes: 3

Thuy
Thuy

Reputation: 1655

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

Upvotes: 0

Aaron Reed
Aaron Reed

Reputation: 984

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

Upvotes: 0

Joey Cai
Joey Cai

Reputation: 20067

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

Upvotes: 10

Related Questions