Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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' inorder to run my executable to run in x86 and x64 bit windows operating systems.

Application executes flawlessly if its target platform is 'x86', but raising the above exception while executing in platform target 'Any CPU'.

this is code in MainWindow
C#
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
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    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,>)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,>();
                //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);
        }
    }
}
Posted
Updated 8-Aug-13 0:27am
v3
Comments
lukeer 8-Aug-13 5:52am    
And what code is there at line number '4' and line position '9'?

Use the "Improve question" link above and provide the relevant code snippet.
Wrap it in tags like these:<pre lang="c#">YourCodeHere();</pre>
Siddharth Koya 8-Aug-13 6:16am    
line number '4' and line position '9 are nothing but Base Class Libraries... we are using " open webkit sharp" dll ..which i dont think will work in x64 bit platform
woopsydoozy 8-Aug-13 9:42am    
Makes sense. The error says your constructor on MainWindow is failing on line 4. Line 4 is your instantiation of WebKitBrowser. Try commenting out third party stuff and seeing if you compile. Then put the 3rd party stuff back in little by little to narrow down where your problem is.

1 solution

The issue is your third party components. One of them (or all of them) were built for x86 and not Any CPU. When you compile an application, you need to use settings for the lowest common denominator. Your only option is to stick with x86 or get an Any CPU build for third party components.

Any particular reason you need "Any CPU"?
 
Share this answer
 
Comments
sandeepams 9-Aug-13 0:47am    
yes, the executable generated using this code must work in x86 and x64 bit windows operating system.
virusstorm 9-Aug-13 8:42am    
A 64-bit system will run a 32-bit application. A 32-bit system will not run a 64-bit application without a component like WOW64 (Windows on Windows 64-bit). So targeting the application for 32-bit (x86) you should be fine. Easiest way to prove this is build two virtual machines. One as 64-bit OS and with a 32-bit OS and test it out. You can use VMware Player to achieve this.
sandeepams 9-Aug-13 1:35am    
the third party components we are using is openwebkitsharp version-3.0, could you tell me whether this third party components 'https://code.google.com/p/open-webkit-sharp/' are compatible with x64 version.
virusstorm 9-Aug-13 8:45am    
I'm not seeing anything that says how this is built, but you can you use this:
http://stackoverflow.com/questions/270531/how-to-determine-if-a-net-assembly-was-built-for-x86-or-x64

That should help you figure out what CPU the DLL is targeted for.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900