Programming has come a long way since the early Assembly days. However, as easy as coding is today, programmers can still run into random bugs and errors from time to time.
In this article, we’re talking about how to fix the ‘error: metadata-generation-failed’ problem in C#.
Upgrade .NET SDK
One of the main causes of this error is your Microsoft.NET.Sdk.Functions package is outdated. Update the package to the latest version and then delete the netstandard1.0 folder located at the path given below.
Check your function names
If your code references two or more function apps with the same function name in the FunctionNameAttribute property, changing the names of the functions so they have unique attributes can fix the problem.
Clean Git branch and rebuild
Sometimes the error can get triggered because of too many untracked files in the Git branch. Cleaning the branch and rebuilding the code can fix this problem. You can use the following command to clean your branch.
git clean -xdf
Do keep in mind that the command will clean the branch of all untracked files, so make sure to save your files and commit any important changes first. Once you’re done, clean the previous build’s output and rebuild the program.
Reinstall Visual Studio Code with .NET Core components
Another cause of the error is the .NET Core 3.1 (LTS Runtime) component missing from Visual Studio Code. To fix this, you will have to completely uninstall VS Code and any components and extensions you’ve installed.
Once the uninstall is complete, reinstall VS Code and this time, make sure that the .NET Core 3.1 (LTS Runtime) component is enabled during installation. Try rebuilding your code once you’re certain and the installation is complete.
Also read: How to fix ‘Clang: Error: No input files’?