c# - '调用与指定绑定(bind)约束匹配的类型的构造函数引发异常

标签 c# xaml exception-handling

所以我正在尝试构建一个访问 Etsy 的 API 的程序,到目前为止我正在尝试做的就是使用 OAuth 调用它并抛出此异常。

'The invocation of the constructor on type 'testEtsy.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '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");
        }

    }
}

如有任何帮助,我们将不胜感激。

最佳答案

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

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

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

关于c# - '调用与指定绑定(bind)约束匹配的类型的构造函数引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15306233/

相关文章:

c# - 我是否干净地编写了这个异常处理?

c# - WPF TabControl - 无法以编程方式选择选项卡

c# - WPF 简单绑定(bind)

c# - 这些 try/catch 是等价的吗?

java - junit如何处理异常

c# - 当从 F# 使用 AvalonEdit 时,CompletionWindow(CodeCompletion 命名空间)中的白线而不是文字

c# - 使用表单例份验证返回登录屏幕

c# - WPF 自定义形状

c# - 如何在我的 View 模型中访问日历控件中的选定日期?

c# - Application.ThreadException 与 AppDomain.UnhandledException