I built a small C# web API using ASP.NET, mostly following this YouTube video. The project runs perfectly fine on Visual Studio Code. However, when I try to open the same folder with Visual Studio and run program.cs
, I get the following error message:
Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I'm using ASP.NET Core Runtime 6.0.5, and I believe that's where the problem is (please correct me if I'm wrong). However, I don't know how to fix the issue. I tried reading this article, but I don't have App.config
file for web APIs. I also tried to read .NET's known issue report, didn't really tell me what exactly should I do to fix the problem.
Any help and insights are appreciated. I'll also share any relevant code and package version information. Thanks!
Update
The problem is now fixed, although I'm not sure how exactly. Here are the steps I took:
1 - From VS code, create a new project using dotnet new webapi --framework net6.0
command line.
2 - Delete WeatherForecast.cs
and WeatherForecastController.cs
, if they got automatically created.
3 - Copy every C# file I wrote from the last project to this one, including program.cs
.
4 - Close VS code. Open the project folder with Visual Studio and select File -> New -> Project From Existing Code -> (What type of project would you like to create?) C#.
One thing I noticed about the working project is that the project icon is different (before it was a green "C#" and wasn't working, now it looks like a blue globe representing web project, although both were C# project and had a .csproj file). Hope that helps.