C# ';对与指定绑定约束匹配的类型调用构造函数时引发异常
所以我试图构建一个访问Etsy API的程序,到目前为止,我所做的只是使用OAuth调用它,它抛出这个异常 '对与指定绑定约束匹配的类型'testEtsy.MainWindow'调用构造函数时引发异常。'行号'3'和行位置'9' 这是我的XAMLC# ';对与指定绑定约束匹配的类型调用构造函数时引发异常,c#,xaml,exception-handling,C#,Xaml,Exception Handling,所以我试图构建一个访问Etsy API的程序,到目前为止,我所做的只是使用OAuth调用它,它抛出这个异常 '对与指定绑定约束匹配的类型'testEtsy.MainWindow'调用构造函数时引发异常。'行号'3'和行位置'9' 这是我的XAML <Window x:Class="testEtsy.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="ht
<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");
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
Net系统;
使用系统文本;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
名称空间测试
{
///
///MainWindow.xaml的交互逻辑
///
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
}
字符串[]orderNumbers=System.IO.File.ReadAllLines(@“F:\orderNumbers.txt”);
公共静态void getOAuthKey()
{
字符串ConsumerKey=“q6uqzk27z2yw4tl5s4qerdtp”;
字符串ConsumerSecret=“tkjz2mu4x1”;
OAuth.Manager m=新的OAuth.Manager();
m[“消费者密钥”]=消费者密钥;
m[“消费者秘密”]=消费者信任;
OAuth.OAuthResponse请求令牌=
m、 收单机构请求令牌(“https://openapi.etsy.com/v2/oauth/request_token?scope=transactions_r“,”职位“);
}
}
}
任何帮助都将不胜感激。最有可能出现的异常是以下字段初始值设定项
string[] orderNumbers = System.IO.File.ReadAllLines(@"F:\ordernumbers.txt");
此代码将作为
main窗口
构造函数的一部分运行。如果在读取文件时发生异常,这将从构造函数中释放并导致初始化失败。最可能的原因是此文件不存在或无法访问项目的目标可能与第三方库的目标不同。作为快速测试,将平台目标(在Project->Properties->Build下)更改为x86。如果可以的话,请检查所有的外部lib是否为64位,否则只需构建x86而不是“任何CPU”。对我来说,罪魁祸首是WebsocketSharp,因为您看起来像OAuth库?您应该在类似“Window\u Loaded”的事件中移动此类代码。它仍然会失败,但您将看到真正的异常。