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");
        }

    }
}

任何帮助将不胜感激。

4

2 回答 2

12

最有可能的异常是以下字段初始值设定项

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

此代码将作为MainWindow构造函数的一部分运行。如果在读取文件时发生异常,这将传播出构造函数并导致初始化失败。最可能的原因是该文件不存在或无法访问

于 2013-03-09T01:51:26.200 回答
3

您项目的目标可能与第三方库的目标不同。就像快速测试一样,将您的平台目标(在项目 -> 属性 -> 构建下)更改为 x86。如果可行,请检查您拥有的任何外部库是否为 64 位,否则只需构建所有 x86 而不是“任何 CPU”。对我来说,罪魁祸首是 WebsocketSharp,因为你看起来像 OAuth 库?

于 2015-05-12T13:04:54.480 回答