Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'The invocation of the constructor on type that matches the specified binding constraints threw an exception

So I'm trying to build a program that accesses Etsy's API and so far all I am trying to do is make a call to it using OAuth and it throws this exception.

'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'.

Here is my 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>

And here is my code in the 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");
        }

    }
}

Any help would be greatly appreciated.

like image 200
Cistoran Avatar asked Dec 06 '22 09:12

Cistoran


1 Answers

The most likely of the exception is the following field initializer

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

This code will run as a part of the MainWindow constructor. If an exception occurs while reading the file this will propragate out of the constructor and cause initialization to fail. The most likely cause is that this file doesn't exist or is inaccessible

like image 67
JaredPar Avatar answered Dec 31 '22 05:12

JaredPar