2013-03-09 13 views
4

所以我試圖構建一個訪問Etsy的API的程序,到目前爲止我所要做的就是使用OAuth調用它它會拋出這個異常。'對匹配指定綁定約束的類型的構造函數的調用引發異常

testEtsy.MainWindow「上類型構造函數的調用‘’匹配指定綁定約束引發了異常。」行號「3」和行位置「9」。

這是我的XAML

<Window x:Class="testEtsy.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525"> 
<Grid></Grid> 

這裏是我在MainWindow.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 

namespace testEtsy 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 

     } 
     string[] orderNumbers = System.IO.File.ReadAllLines(@"F:\ordernumbers.txt"); 

     public static void getOAuthKey() 
     { 

      string ConsumerKey = "q6uqzk27z2yw4tl5s4qerdtp"; 
      string ConsumerSecret = "tkjz2mu4x1"; 
      OAuth.Manager m = new OAuth.Manager(); 
      m["consumer_key"] = ConsumerKey; 
      m["consumer_secret"] = ConsumerSecret; 
      OAuth.OAuthResponse requestToken = 
       m.AcquireRequestToken("https://openapi.etsy.com/v2/oauth/request_token?scope=transactions_r", "POST"); 
     } 

    } 
} 

任何幫助將不勝感激代碼。

回答

10

最有可能的例外是以下字段初始

string[] orderNumbers = System.IO.File.ReadAllLines(@"F:\ordernumbers.txt"); 

此代碼將運行作爲MainWindow構造的一部分。如果在讀取文件時發生異常,則會阻塞構造函數,導致初始化失敗。最可能的原因是此文件不存在或無法訪問

+0

您應該在「Window_Loaded」這樣的事件中移動此類代碼。它仍然會失敗,但你會看到真正的例外。 – Guish 2017-05-05 15:02:12

3

您的項目的目標可能與第三方庫的目標不相同。就像快速測試一樣,將您的Platform目標(在Project - > Properties - > Build下)更改爲x86。如果可行,請檢查您擁有的任何外部庫是否爲64位,否則只需構建所有x86而不是「任何CPU」。對我來說,罪魁禍首是WebsocketSharp,因爲你看起來像OAuth庫?

相關問題