Error in Webbrowser when I waiting for ajax changes - c#

I have a project that reads content from web and saves it to the database.
I use Timer control to wait for ajax changes and it has been working for a long time without any problem.
But unexpectedly it is not working any more. I get the following error :
Exception thrown: 'System.Runtime.InteropServices.COMException' in
SnapshotInfo.exe
Additional information: Error HRESULT E_FAIL has been returned from a
call to a COM component.
Part of the code on this problem :
WebBrowser _browser = new WebBrowser();
private void Form1_Load(object sender, EventArgs e)
{
_browser.Dock = DockStyle.Fill;
_browser.DocumentCompleted += _browser_DocumentCompleted;
Controls.Add(_browser);
}
private void _browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (!timer1.Enabled)
{
// do any thing
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
_browser.Dispose();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (_browser.Document==null || _browser.Document.Body==null) return;
var body = _browser.Document.Body.InnerHtml; // ----> error here
if (body.Contains("word"))
{
// code when word is exist
timer1.Enabled = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
_browser.Navigate(textBox1.Text);
timer1.Enabled = true;
}
I do not know where is the problem?
Thanks for any help

Make sure you are using latest version of web browser control , check below link
Use latest version of Internet Explorer in the webbrowser control
or you can replace web browser control with another web browser engine like http://www.awesomium.com/ it's free and easier to use

The problem solved by deleting the security update KB3087040!

Related

System.FormatException occurred in mscorlib.dll when converting it int32

I know, i know there are lots and lots of questions asking on here about this error, each with their own response, but its easier to work off a response regarding your own code rather than someone else's
I have been working on this program for some time for a college assignment, and as soon as i started putting in the class to calculate the totals of things it now crashes,
I don't know where to look so i'll post my main code
enter code here
namespace Till
public partial class MainWindow : Window
{
Calculator calc = new Calculator();
public MainWindow()
{
InitializeComponent();
}
public bool User;
public bool tillopen = false;
private void button_Click(object sender, RoutedEventArgs e)
{
//button clone thingy
Button btn = (Button)sender;
label.Content = label.Content + btn.Content.ToString();
Console.Beep(); // makes the buttons beep
}
private void clear_Click(object sender, RoutedEventArgs e)
{
// Clear
label.Content = "";
}
private void Button_Submit_Click(object sender, RoutedEventArgs e)
{
// submit
listView.Items.Add(label.Content);
label.Content = "";
calc.setSoldItems(Convert.ToInt32(label.Content)); /// it breaks on this line///
}
private void button13_Click(object sender, RoutedEventArgs e)
{
//void sale
label.Content = "";
listView.Items.Clear();
}
private void button15_Click(object sender, RoutedEventArgs e)
{
//pound
label.Content = "1.00";
}
private void button12_Click(object sender, RoutedEventArgs e)
{
//till open close
tillopen = true;
}
private void button16_Click(object sender, RoutedEventArgs e)
{
Login m = new Login();
m.Show();
this.Close();
}
private void button14_Click(object sender, RoutedEventArgs e)
{
label.Content = "2.00"; // 2 pound
}
private void button17_Click(object sender, RoutedEventArgs e)
{
label.Content = calc.finish();
}
}
I have tried to re-create the error in another WPF (converting a to an int32) and it works fine, i know this is an issue with my code itself, i have tried using other machine and using different versions of visual studio itself, so we came to the assumption its this code itself and not a broken dll file
So before I sit down with my Teacher and spend all day going though my code step by step im asking around for help in order to save both of our time, This assignment is due in in 3 weeks, and it decides to break on me now.
thankies
To replicate this error, i press a number button on my Windows form, them hit the submit button i created (which starts the conversion) If a copy of my class which handles all of this is needed im happy to post it
In the method button_click, you have assigned value as
label.Content = label.Content + btn.Content.ToString();
which is a string value to the label and the values are concatenated instead of add.
and when you are reading it, you are converting it in Int32. which will give exception as it will not contain any integer value to it.
You can add the value like this:
label.Content = (Convert.ToInt32(label.Content) + Convert.ToInt32(btn.Content)).ToString();
and check before converting if the label has blank values in it, if it has do not convert them, and only convert the value if it has some values it will not give any error. Also do not assign any values other that numerical digits.
You are calculating:
Convert.ToInt32(label.Content)
but on the line before you set:
label.Content = "";
so this means you are calculating
Convert.ToInt32("")
which gives you a FormatException.
Perhaps you should use the value of label.Content before you overwrite it?

Preventing navigation to ChildWindow in Silverlight

When we try to navigate to ChildWIndow using AddressString of the Browser the method
private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
does not executing.
And instead of the error happens here
private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
e.Handled = true;
// ErrorWindow.CreateNew(e.Exception);
}
How to prevent to navigate to the ChildWindow?
Thank you!

Using firefox to open c# url button not default browser

I have a very simple program that has 4 buttons each button opens a url.
What i would like is to get each button to use Firefox as the default browser.
I know i can set it as the default browser and then it will work however if a user sets internet explorer as the defualt it will open in that instead.
These url only work in Firefox as it has certificate issues.
So essentially my question is how can i change my code to make sure that if you click on any of the 4 buttons, that it will open up in firefox and not internet explorer.
Here is my code
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://192.168.2.56/dummy.htm?settings=save&user_active1=on");
BtnOff.BackColor = Color.Red;
Bnton.BackColor = Color.Chartreuse;
}
private void button2_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://192.168.2.56/dummy.htm?settings=save&user_active1=off");
Bnton.BackColor = Color.Red;
BtnOff.BackColor = Color.Chartreuse;
}
private void button3_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://217.20.xxx.xxx/api/agent/pause.json?active_host=217.20.xxx.xxx&active_user=3012532&username=buildstore&password=cha9pU7U&client=snom");
BtnDND.BackColor = Color.Chartreuse;
BtnQue.BackColor = Color.Red;
}
private void button4_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://217.20.xxx.xxx/api/agent/unpause.json?active_host=217.20.xxx.xxx&active_user=3012532&username=buildstore&password=cha9pU7U&client=snom");
BtnQue.BackColor = Color.Chartreuse;
BtnDND.BackColor = Color.Red;
}
Thanks for taking the time to look appreciate it.
you can use
System.Diagnostics.Process.Start(#"C:\Program Files (x86)\Mozilla Firefox\firefox.exe", "http://yoursite.com/dummy.htm");
you can keep the path of firefox.exe in config file instead of hard coding. Alternatively set the PATH environment variable.

How to show a windows form as a Dialog into VSTO word addin?

I have a VSTO Project (WinWord addin) using c#.
The Project has only one window, it must be showed when click on some button, the problem is that it only happens when i'm debuging, if i try to use it after run the installation, it doesn't show the window. Here is my ribbon code:
public partial class MyRibbon
{
private void MyRibbon_Load(object sender, RibbonUIEventArgs e)
{
}
private void btnPublicar_Click(object sender, RibbonControlEventArgs e)
{
MyForm form = new MyForm();
//form.TopLevel = true;
form.ShowDialog();
//form.Show();
}
private void gallery1_Click(object sender, RibbonControlEventArgs e)
{
}
private void editBox1_TextChanged(object sender, RibbonControlEventArgs e)
{
}
}
The commented code are some tries. Any help tks.
After very deep debug, found my addin were throwing an non handeled exception (some XML files needed by addin are lost. They weren't where they should), the extrange thing is that Word doesn't show the problem, simply doesn´t open the form.

c# application which detects form fields in a browser

I created a winForm application which fills the fields of a web site :
private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate(new Uri("http://www.site.com”));
this.textBox1.Text = this.webBrowser1.Version.ToString();
}
private void button1_Click (object sender, EventArgs e)
{
System.Windows.Forms.HtmlDocument document =
this.webBrowser1.Document;
document.GetElementById("login").SetAttribute("Value","user");
}
It works perfectly when the web site page is loaded in application control but when I want to open it in a new browser using webBrowser1.Navigate(new Uri("http://www.site.com”),true); the page fields are undetectable.
Is there a solution for this problem? Thanks in advance

Categories