私のコントローラクラスでSystem.Web.Httpライブラリを参照できますが、別のクラスでは参照できないC#プロジェクトがあります。参照はプロジェクト全体に追加され、両方のクラスには必要な指示をすべて使用しています。System.Web.Httpアセンブリが常に同じC#プロジェクトで表示されない
System.Web.HttpのRequestメソッドは、一部のインスタンスでは解決できません。ここで
は、二つのクラスのコードスニペットです:
コントローラ/ FormsController.cs
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using System.Web.Http.Description;
using FormsImport.Models;
namespace FormsImport.Controllers
{
public class TCSTasksController : ApiController
{
[Route("api/TCSUploadFile")]
[AllowAnonymous]
public async Task<HttpResponseMessage> UploadCSVFile()
{
try
{
var httpRequest = HttpContext.Current.Request;
foreach (string file in httpRequest.Files)
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created); // <-- the name Request does exists
.
.
.
}
CSVmanager.cs
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http; //<-- Compiler claims this directive is unneccesary
using System.Web.Http.Description;
using FormsImport.Models;
namespace FormsImport
{
public class CSVmgr
{
public async Task<HttpResponseMessage> UploadCSVFile()
{
try
{
var httpRequest = HttpContext.Current.Request;
foreach (string file in httpRequest.Files)
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created); // <-- the name Request Does not exist in the current context
.
.
.
}
'Request'はApiController''のプロパティです。あなたは 'CSVmgr'がどこからそれを得ることを期待していますか? – yaakov
System.Web.Httpは必須ではないと主張しています。あなたは、その名前空間からのタイプを使用したり継承したりしていません。 –
あなたはこれがエラーだと思いますか?この結果、コンパイラのエラーが発生します(不要な 'using'ディレクティブに関する警告に加えて)? – CoolBots