2

I am new to .net/C#. I am trying to build a project but getting a lot of missing reference error. When I am trying to install the packages like mentioned in example, I am getting error that it already exists in the project.

PM> Install-Package Microsoft.AspNet.WebApi.Core
Package 'Microsoft.AspNet.WebApi.Core.5.2.7' already exists in project 'XXXXXXystemApi'
Time Elapsed: 00:00:16.0349189

Also, as in below screenshot, I see that there are few references which have a little warning signs which might be pointing towards what is wrong with my setup.

The type or namespace name 'Http' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

enter image description here

I tried to Add references to the project but I am not seeing any entry for System.Web.Http under add reference dialog.

How do I fix all this ?

Naxi
  • 1,504
  • 5
  • 33
  • 72
  • Did you install [Microsoft.AspNet.WebApi.Core](https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Core/)? Or [Microsoft.AspNet.WebApi.Owin](https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Owin)? – mm8 Dec 03 '20 at 14:48
  • Yes. Tried installing using nuget as shown in the screenshot. It says it's already exist in the project. – Naxi Dec 03 '20 at 14:52
  • Is this actual a asp core project or asp.net? Seems a bit mixed up. [You can not use System.Web in a asp core project](https://stackoverflow.com/questions/40912473/can-system-web-be-used-with-asp-net-core-with-full-framework/40912731) – nilsK Dec 03 '20 at 14:53
  • @nilsK from what I know this is an already built product up and working in prod. Things are messed up just in my local. – Naxi Dec 03 '20 at 14:56
  • What you linked to is another question, not an example. It may have nothing at all to do with your problem and could make things worse. If that's an already build product, delete your local copy and start from scratch. One way or another you've mixed ASP.NET Core and ASP.NET Old classes. – Panagiotis Kanavos Dec 03 '20 at 15:00
  • Have you installed the .NET SDK version that's required by your project? Have you tried building *without* adding any extra packages? – Panagiotis Kanavos Dec 03 '20 at 15:02
  • @PanagiotisKanavos I did install .NET Framework 4.6.2 Developer Pack. And I am not adding any extra packages. I did a fresh git pull and built the solution. It fails right there. No changes from my end. – Naxi Dec 03 '20 at 15:06
  • 1
    `Install-Package` installs a new extra package. Have you tried restoring the *existing* packages? Older VS versions didn't restore automatically when building for the first time – Panagiotis Kanavos Dec 03 '20 at 15:08
  • What version of Visual Studio? – Ian Kemp Dec 03 '20 at 15:11
  • @IanKemp VS 2019 professional – Naxi Dec 03 '20 at 15:14
  • @PanagiotisKanavos How do I do it ? Is there a cmd for it ? – Naxi Dec 03 '20 at 15:14
  • Production and the other systems may have different versions of the framework installed on them, or different assemblies in the GAC, etc, so I would check the versions. You can also use fuslogvw to help you troubleshoot runtime binding issues. – Dan Csharpster Dec 03 '20 at 18:56

2 Answers2

1

Try running

dotnet restore

in the Package Manager Console

Also, unloading and reloading the project has worked for me before (Right-click on the project name in the Solution explorer to unload and reload)

BMiller
  • 19
  • 1
  • I get this: The term 'dotnet' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. – Naxi Dec 04 '20 at 06:42
0

Here is what finally solved my problem.

use NuGet and downgrade a version of library you are having issue with ; then re-install the right version. Accept Licenses (which is probably what was needed). Important: close and reopen visual studio.

Reference link : solution ref

Naxi
  • 1,504
  • 5
  • 33
  • 72