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:
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....:
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?