0

I apologize for this question, but I am absolutely new to .NET development (coming from Java...) I am trying to test this example of API:

https://learn.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

My code complains on "Cannot Resolve": using System.Net; using System.Web.Http; ApiController IHttpActionResult

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web.Http;
using WebApiSandobox01.Models;

namespace WebApiSandobox01.Controllers
{
    public class ProductsController:ApiController
    {
        Product[] products = new Product[] 
        { 
            new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 }, 
            new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M }, 
            new Product { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M } 
        };`enter code here`

        public IEnumerable<Product> GetAllProducts()
        {
            return products;
        }

        public IHttpActionResult GetProduct(int id)
        {
            var product = products.FirstOrDefault((p) => p.Id == id);
            if (product == null)
            {
                return NotFound();
            }
            return Ok(product);
        }
    }
}

I have Rider 2022.1 as IDE I went through this question (unfortunately Nuget is little bit different in 2022, ...):

System.Net, cannot resolve symbol 'Net'

Going to Project -> properties, Target Framework is: .NETFramework v.4.8

I have .NETFramework v.4.8 Developer Pack installed in:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.8

I can see files:

System.Net.dll System.Net.Http.dll System.Net.Http.WebRequest.dll

Under Settings -> Toolset & Build I tried various MS Build versions (4.0, 17.0) - No difference

Can you advice me, how to resolve this? I am relly new to .NET and Rider. I have spent almost one day on this already....

Let me specify, what I want to achieve in this way, also reacting on your questions:

Currently I am trying to create "sandbox", anything, which will resemble technologies above, eg:

  • due to my experiences with IntelliJ, I have chosen Rider
  • using CLR (I would like my code to be "indpendent" as Java)
  • use IIS (as Tomcat in Java world)
  • therefore I do not want to create .exe ( I was able to create, using template ASP.NET Core Web API the service, but it is .exe file)
  • when I use dotnet new --list, there is no other template for API other than ASP.NET Core Web API)

Bellow mentioned link again has Program.cs file....:

https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-6.0&tabs=visual-studio-code

Yes, I found that Rider has "AddReference", but it does not allow to add "System.Web.Http" to resolve [ApiController] reference

Do you know about some simple example code, which can create RestService, running on top of IIS, using CLR with Net6.0?

jirka
  • 41
  • 5
  • 1
    If you're new to .NET, then why are you starting out with ASP.NET Web API? That's been superseded by the [Web API functionality in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-6.0&tabs=visual-studio). – mason Apr 24 '22 at 13:36
  • 1
    Can you share project file – Maytham Fahmi Apr 24 '22 at 13:38
  • Are you trying .Net Framework in .Net Core? – Reza Heidari Apr 24 '22 at 13:38
  • I would recommend downloading vs 2022 community and trying to build there. It's not quite clear if your ide messes here or it's your fault. VS would allow you to right click the class and add correct references from a context menu. – Wiktor Zychla Apr 24 '22 at 13:42
  • Rider can add all references to the project also of course. Try to click `alt+enter` on red symbols. These references pretty much like libraries in java. Try to find them in the solution explorer under `dependencies` node – xtmq Apr 24 '22 at 13:59
  • If this is just a toy project you created to study C#/.NET, share it on GitHub so everyone can see your code. Without that, it is impossible to guess what you are working at and what's wrong. – Lex Li Apr 25 '22 at 00:53
  • Thank you very much for recommendations, I have updated my question to explain, what I want to achieve.. I really apologize for my confusion regarding MS .NET.... As written, I am coming from Java, IntelliJ Idea, SpringBoot, JPA type of environment... Do you know about some simple example code, which can create RestService, running on top of IIS, using CLR? Really I am lost.... – jirka Apr 26 '22 at 14:49

0 Answers0