2017-10-01 12 views
0

これはよくある質問ですが、回答が見つかりませんでした。私は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); 
      } 



     } 

    } 
} 
+1

コンパイラはどの行にポイントしますか?きれいなビルドはありますか?ソリューションを完全に再構築して、各アセンブリがビルドされるように設定されている場合はConfiguration Managerを確認してください。 – Waescher

+0

これは、Form1宣言である19行目を指しています。これは再構築エラーです。しかし、提案をありがとう。 – Xenopod

+1

ここでは、この行はこの行です。ここには行番号はなく、19行目に空白行があります。 – Waescher

答えて

0

実際には提供されているコードには問題があります。 IDEは問題がフォームにあると思っていましたが、自動コードジェネレータはフォームを確立するのではなく名前空間を使用しました。エラーフォームは、フォームの19行目に問題があると考えましたが、実際はprogram.csファイルの先頭にありました。これが頻繁に起こらないことを願っています。

2

私はあなたの形式でInitializeComponent()後にセミコロンを嫌うだろう。

 InitializeComponent(); <--- !!! 
     { 
      textBox1.Text = ("Enter the path to a JPEG image file:"); 
      ... 
     } 
+0

しかし、ポインタのおかげで。問題は実際にはprogram.csファイルにありましたが、IDEはフォーム自体にあると思っていました。 – Xenopod

関連する問題