3

The invocation of the constructor on type 'WpfApplication1.MainWindow' that matches the specified binding constraints threw an exception.' Line number '4' and line position '9'.

That was the error I'm facing while changing my target platform from 'x86' to 'Any CPU' in order to run my executable to run in x86 and x64 bit windows operating systems.

using System;
using System.Collections.Generic;
using System.Linq;
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;
using WebKit;
using WebKit.Interop;
using Twitterizer;
using Facebook;
using TwitterConnect;
using facebook;

namespace WpfApplication3
{   
public partial class MainWindow : Window
{
    public MainWindow()
    {
            InitializeComponent();

        }

    WebKitBrowser wb = new WebKitBrowser();
    TwitterConnect.TwitterStuff ts = new TwitterStuff();
    Browser b = new Browser();
    OpenWebkitBrowser.facebook fb_1 = new OpenWebkitBrowser.facebook();

    private void Possibillion_Loaded(object sender, RoutedEventArgs e)
    {
        System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
        host.Child = wb;
        this.Grid2.Children.Add(host);
        wb.DocumentCompleted += wb_DocumentCompleted;
    }

    void wb_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
    {
        textBox1.Text = wb.Url.ToString();
        TabItem1.Header = wb.DocumentTitle;
    }

    private void btnMinimize_Click(object sender, RoutedEventArgs e)
    {
        Possibillion.WindowState = WindowState.Minimized;
    }

    private void btnMaximize_Click(object sender, RoutedEventArgs e)
    {
        if (Possibillion.WindowState == WindowState.Maximized)
            Possibillion.WindowState = WindowState.Normal;
        else
            Possibillion.WindowState = WindowState.Maximized;
    }

    private void btnClose_Click(object sender, RoutedEventArgs e)
    {
        Possibillion.Close();
    }

    private void btnGo_Click(object sender, RoutedEventArgs e)
    {
        wb.Navigate("http://" + textBox1.Text);
    }

    private void btnTwitter_Click(object sender, RoutedEventArgs e)
    {
        bool loggedIn = b.AlreadyLoggedIn();

        if (!loggedIn)
        {
            //this.Hide();
            b.Show();
        }
        //else
        //{
        //    MainWindow mw = new MainWindow();
        //    mw.Show();
        //    this.Close();
        //}



        else if (textBox1.Text != "")
        {
            ts.tweetIt(wb.DocumentTitle);
            //textBox1.Clear();
        }
    }

    private void btnfacebook_Click_1(object sender, RoutedEventArgs e)
    {
        if (val.login == true)
        {
            //fb_1.Show();
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                Dispatcher.Invoke(new Action(() => { System.Windows.MessageBox.Show("Enter message."); }));
                return;
            }

            var fb = new FacebookClient(val.token);

            fb.PostCompleted += (o, args) =>
            {
                if (args.Error != null)
                {
                    Dispatcher.Invoke(new Action(() => { System.Windows.MessageBox.Show(args.Error.Message); }));
                    return;
                }

                var result = (IDictionary<string, object>)args.GetResultData();
                //_lastMessageId = (string)result["id"];

                Dispatcher.Invoke(new Action(() =>
                {
                    System.Windows.MessageBox.Show("Message Posted successfully");

                    textBox1.Text = string.Empty;
                    // pho.IsEnabled = true;
                }));
            };
            var fbimg = new Facebook.FacebookMediaObject
            {
                FileName = Guid.NewGuid() + ".jpg",
                ContentType = "image/png"
            };

            //  FileStream fs = new FileStream("Rose.png", FileMode.Open, FileAccess.Read);
            //  BinaryReader br = new BinaryReader(fs);
            //  byte[] res = br.ReadBytes((int)fs.Length);
            //  br.Close();
            //  fs.Close();
            //fbimg.SetValue(res);
            //   Uri uri = new Uri("/Background.png",UriKind.Relative);
            var parameters = new Dictionary<string, object>();
            //parameters.Add("picture", fbimg);
            //parameters.Add("message", "hi");
            // parameters["picture"] ="https://twimg0-a.akamaihd.net/profile_images/2263781693/SAchin_reasonably_small.png";
            parameters["message"] = textBox1.Text;
            //  parameters["picture"] =fbimg;
            //fb.PostAsync(@"/photos", parameters);
            fb.PostAsync("me/feed", parameters);
        }
        else
        {
            Dispatcher.Invoke(new Action(() => { fb_1.ShowDialog(); }));
            //System.Windows.MessageBox.Show("message not sent");

        }
    }

    private void textBox1_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
            wb.Navigate("http://" + textBox1.Text);
    }
}
}
Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
Siddharth Koya
  • 103
  • 3
  • 16
  • " The invocation of the constructor on type 'WpfApplication1.MainWindow' that matches the specified binding constraints threw an exception.' Line number '4' and line position '9'. " This is the Exception we get – Siddharth Koya Aug 08 '13 at 10:13
  • do you have any inner exception? and could you post the stackstrace please – makim Aug 08 '13 at 10:16
  • This is the inner Exception {"Could not load file or assembly 'OpenWebKitSharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format."} – Siddharth Koya Aug 08 '13 at 10:27
  • 1
    @SiddharthKoya Go step by step at the constructor. You will find that it's not a XAML exception really, but as it's launched during the constructor, it seems so. – Sonhja Aug 08 '13 at 10:28
  • As soon as start my project this problem occurs .. but when i change Target Platform to x86 it executes flawlessly – Siddharth Koya Aug 08 '13 at 10:30
  • could it be that the OpenWebKitSharp is a 64bit DLL? – makim Aug 08 '13 at 10:32
  • @ Sine: there two sets of DLL's Available one set is for Target Framework above 3.5 and other Dll's is for Framework 2.0 and 3.5 – Siddharth Koya Aug 08 '13 at 10:34

1 Answers1

0

Make sure your target platform matches your build settings.

If you have changed your configuration manager to any CPU, then in the project properties under build you will need to do the same.

Edit - Ah seems like your trying to run a toolkit that is build for x86 in a x64 world.

Mark Jones
  • 36
  • 2
  • @ Mark Jones i am using OpenWebsharp DLL when i deploy the Project it install's and works flawlessly in 32 bit system(windows) but when come to 64 bit The Application Install's but when i double click on shortcut in Desktop it wont open – Siddharth Koya Aug 08 '13 at 10:36
  • You just need to put the application back to x86, it will still run in x64 windows, it just wont gain access to any extended memory. – Mark Jones Aug 09 '13 at 08:10
  • @ Mark jones:when we change the application to x86 and when we deploy the project and create an EXE it installs in both WIN 7(32 bit and 64 bit) ..but application only opens in 32 bit .. that the problem .. – Siddharth Koya Aug 09 '13 at 11:16