ExecutionEngineException using AxSHDocVw.AxWebBrowser

S

sagar.jawale

Hi,

In my c# windows application, i am using AxSHDocVw.AxWebBrowser.
I am displaying a generated receipt html in this browser. Also,
for printing the same html, i am using the following command :

axWebBrowser2.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,ref empty,ref
empty);

This works fine and Html is printed properly on some machines.
But on some machines, it is giving ExecutionEngineException or
sometimes
it is giving StackOverflowExceptions. Since as per the microsoft site,

we cannot catch these both types of exceptions at all.
Also, i cannot debug the occured exception, because it is occuring
only on client machines.

Can anyone pls help me to solve this problem?

Thanks & Regards,
Sagaraj

Here is the entire code :
-----------------------------------

using System;
using System.Drawing;
using System.Data;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.IO;
using System.Diagnostics;

public class FrmPaymentReceipt : System.Windows.Forms.Form
{
public const string YES = "Y";
public const string NO = "N";
public const int PERCENTAGE=100;
private PaymentReceiptDS paymentReceiptDS;
ulong subTotal = 0;
float tax=0;
decimal saleAmount=0;
decimal returnAmount=0;
decimal saleAmt_Minus_ReturnAmt=0;
private AxSHDocVw.AxWebBrowser axWebBrowser2;
private XmlDocument xmlDoc;
bool printFlag=true;

public FrmPaymentReceipt()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

this.Visible = false;

}

public FrmPaymentReceipt(PaymentReceiptDS paymentReceiptDS,
bool printFlag)
{
//
// Required for Windows Form Designer support
//
this.Visible = false;
InitializeComponent();
this.paymentReceiptDS = paymentReceiptDS;
this.printFlag = printFlag;
this.Visible = false;
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources =
new System.Resources.ResourceManager(typeof(FrmPaymentReceipt));
this.axWebBrowser2 = new AxSHDocVw.AxWebBrowser();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser2)).BeginInit();
this.SuspendLayout();
//
// axWebBrowser2
//
this.axWebBrowser2.Enabled = true;
this.axWebBrowser2.Location = new System.Drawing.Point(88, 148);
this.axWebBrowser2.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser2.OcxState")));
this.axWebBrowser2.Size = new System.Drawing.Size(300, 150);
this.axWebBrowser2.TabIndex = 1;
this.axWebBrowser2.Visible = false;
//
// FrmPaymentReceipt
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(720, 448);
this.ControlBox = false;
this.Controls.Add(this.axWebBrowser2);
this.Name = "FrmPaymentReceipt";
this.Load += new System.EventHandler(this.FrmPaymentReceipt_Load);
this.Activated += new
System.EventHandler(this.FrmPaymentReceipt_Activated);
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser2)).EndInit();
this.ResumeLayout(false);

}
#endregion

private void FrmPaymentReceipt_Load(object sender, System.EventArgs e)
{
this.Visible = false;
this.CalculateBalance();
this.ArticleSaleReturnAmount();
string xmlSchema = this.paymentReceiptDS.GetXml();
this.Visible = false;
xmlSchema =
xmlSchema.Replace("xmlns=\"http://tempuri.org/ReceiptDS.xsd\"","");
this.Visible = false;
xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlSchema);
this.Visible = false;
XmlTextWriter writer =
new XmlTextWriter("receipt.xml",System.Text.Encoding.UTF8);
writer.WriteStartDocument(true);
this.Visible = false;
writer.WriteProcessingInstruction("xml-stylesheet",
"type=\"text/xsl\" href=\"receipt.xsl\"");
writer.WriteRaw(xmlSchema);
writer.Close();
xmlDoc.CreateProcessingInstruction("xml-stylesheet",
"type=\"text/xsl\" href=\"receipt.xsl\"");
this.Visible = false;
this.InitializeReport();
this.Visible = false;
}

private void InitializeReport()
{
this.Visible = false;
string strxslName = "receipt.xsl";

if (this.paymentReceiptDS.RETURN_PARTICULARS.Rows.Count<=0)
{
}
else
{
strxslName = "receiptreturn.xsl";
}

StringWriter sw;
sw = MergeXSL_XML("receipt.xml",strxslName);
System.IO.StreamWriter file =
new System.IO.StreamWriter("receipt.html");
file.WriteLine(sw.ToString());
file.Close();

object empty = System.Reflection.Missing.Value;
axWebBrowser2.Navigate("about:blank",ref empty,ref empty,
ref empty,ref empty);
mshtml.IHTMLDocument2 htmlDoc =
(mshtml.IHTMLDocument2) axWebBrowser2.Document;
htmlDoc.writeln(sw.ToString());

this.Visible = false;
Object a = new object(),b = new object();

if(System.Configuration.ConfigurationSettings.AppSettings["ExecutionMode"]!="Testing")
{
if (printFlag)
{
axWebBrowser2.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
ref empty,ref empty );
axWebBrowser2.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
ref empty,ref empty );
}
}
this.Visible = false;
}

public StringWriter MergeXSL_XML(string xml, string xsl)
{
try
{
//XPathDocument xPath = new XPathDocument(xml);

XslTransform xTrans = new XslTransform();
xTrans.Load(Application.StartupPath+ "\\"+ xsl);
StringWriter strW = new StringWriter();
xTrans.Transform(xmlDoc,null,strW);
strW.Close();
return strW;
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
return null;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top