これはよくある質問ですが、回答が見つかりませんでした。私はMicrosoft Emotion APIを試しています(これは質問のためにここにジェネリックキーを使用しています)。そして、 "WindowsFormsApp2
は名前空間ですが、タイプとして使用されています"名前空間。私はより適切なタイトルに名前空間を変更しましたが、実際にはコード内に存在しなかったにもかかわらず、WindowsFormsApp2
が型として不適切に使用されたというビルドエラーを受けました。私はそれがこの問題を作り出していることをどこで使っているのか分かりません。ここで"FormsAppは名前空間ですが、タイプのように使用されます"
は私のコードです:
using System.Windows.Forms;
using System.IO;
using System.Net.Http.Headers;
using System.Net.Http;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
{
textBox1.Text = ("Enter the path to a JPEG image file:");
openFileDialog1.ShowDialog();
string imageFilePath = openFileDialog1.FileName;
MakeRequest(imageFilePath);
textBox1.Text = ("\n\n\nWait for the result below, then hit ENTER to exit...\n\n\n");
}
byte[] GetImageAsByteArray(string imageFilePath)
{
FileStream fileStream = new FileStream(imageFilePath, FileMode.Open, FileAccess.Read);
BinaryReader binaryReader = new BinaryReader(fileStream);
return binaryReader.ReadBytes((int)fileStream.Length);
}
async void MakeRequest(string imageFilePath)
{
var client = new HttpClient();
// Request headers - replace this example key with your valid key.
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "13hc77781f7e4b19b5fcdd72a8df7156");
// NOTE: You must use the same region in your REST call as you used to obtain your subscription keys.
// For example, if you obtained your subscription keys from westcentralus, replace "westus" in the
// URI below with "westcentralus".
string uri = "https://westus.api.cognitive.microsoft.com/emotion/v1.0/recognize?";
HttpResponseMessage response;
string responseContent;
// Request body. Try this sample with a locally stored JPEG image.
byte[] byteData = GetImageAsByteArray(imageFilePath);
using (var content = new ByteArrayContent(byteData))
{
// This example uses content type "application/octet-stream".
// The other content types you can use are "application/json" and "multipart/form-data".
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response = await client.PostAsync(uri, content);
responseContent = response.Content.ReadAsStringAsync().Result;
}
//A peak at the JSON response.
textBox1.Text = (responseContent);
}
}
}
}
コンパイラはどの行にポイントしますか?きれいなビルドはありますか?ソリューションを完全に再構築して、各アセンブリがビルドされるように設定されている場合はConfiguration Managerを確認してください。 – Waescher
これは、Form1宣言である19行目を指しています。これは再構築エラーです。しかし、提案をありがとう。 – Xenopod
ここでは、この行はこの行です。ここには行番号はなく、19行目に空白行があります。 – Waescher