我知道这是一个经常被问到的问题,但我找不到答案。我正在尝试一个Microsoft Emotion API(我在这里使用通用密钥来提问),并且它一直给我错误,“WindowsFormsApp2
是一个命名空间但是用作一个类型”即使我更改命名空间。我将命名空间更改为更合适的标题,但我仍然收到WindowsFormsApp2
被不恰当地用作类型的构建错误,尽管它在代码中没有任何地方。我不知道我在哪里使用它,它正在创建这个问题。
这是我的代码:
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);
}
}
}
}
答案 0 :(得分:2)
我不喜欢你// test.py
from tag36h11_detector import detect
import numpy as np
a = np.array([1,2,3], dtype=np.uint8)
detect(4, 5, a)
之后的分号。
InitializeComponent()
答案 1 :(得分:0)
我发现了问题,实际上并不在提供的代码中。 IDE认为问题出在表单中,但自动代码生成器使用命名空间而不是建立表单。错误形式认为问题出现在表单的第19行,但它实际上是在program.cs文件的开头。我希望这不会经常发生。