Hi,
In my c# windows application, i am using AxSHDocVw.AxWeb Browser.
I am displaying a generated receipt html in this browser. Also,
for printing the same html, i am using the following command :
axWebBrowser2.E xecWB(SHDocVw.O LECMDID.OLECMDI D_PRINT,
SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DONTPROMP TUSER,ref empty,ref
empty);
This works fine and Html is printed properly on some machines.
But on some machines, it is giving ExecutionEngine Exception or
sometimes
it is giving StackOverflowEx ceptions. 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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Xml;
using System.Xml.XPat h;
using System.Xml.Xsl;
using System.IO;
using System.Diagnost ics;
public class FrmPaymentRecei pt : System.Windows. Forms.Form
{
public const string YES = "Y";
public const string NO = "N";
public const int PERCENTAGE=100;
private PaymentReceiptD S paymentReceiptD S;
ulong subTotal = 0;
float tax=0;
decimal saleAmount=0;
decimal returnAmount=0;
decimal saleAmt_Minus_R eturnAmt=0;
private AxSHDocVw.AxWeb Browser axWebBrowser2;
private XmlDocument xmlDoc;
bool printFlag=true;
public FrmPaymentRecei pt()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
this.Visible = false;
}
public FrmPaymentRecei pt(PaymentRecei ptDS paymentReceiptD S,
bool printFlag)
{
//
// Required for Windows Form Designer support
//
this.Visible = false;
InitializeCompo nent();
this.paymentRec eiptDS = paymentReceiptD S;
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.Disp ose();
}
}
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 InitializeCompo nent()
{
System.Resource s.ResourceManag er resources =
new System.Resource s.ResourceManag er(typeof(FrmPa ymentReceipt));
this.axWebBrows er2 = new AxSHDocVw.AxWeb Browser();
((System.Compon entModel.ISuppo rtInitialize)(t his.axWebBrowse r2)).BeginInit( );
this.SuspendLay out();
//
// axWebBrowser2
//
this.axWebBrows er2.Enabled = true;
this.axWebBrows er2.Location = new System.Drawing. Point(88, 148);
this.axWebBrows er2.OcxState =
((System.Window s.Forms.AxHost. State)(resource s.GetObject("ax WebBrowser2.Ocx State")));
this.axWebBrows er2.Size = new System.Drawing. Size(300, 150);
this.axWebBrows er2.TabIndex = 1;
this.axWebBrows er2.Visible = false;
//
// FrmPaymentRecei pt
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 12);
this.ClientSize = new System.Drawing. Size(720, 448);
this.ControlBox = false;
this.Controls.A dd(this.axWebBr owser2);
this.Name = "FrmPaymentRece ipt";
this.Load += new System.EventHan dler(this.FrmPa ymentReceipt_Lo ad);
this.Activated += new
System.EventHan dler(this.FrmPa ymentReceipt_Ac tivated);
((System.Compon entModel.ISuppo rtInitialize)(t his.axWebBrowse r2)).EndInit();
this.ResumeLayo ut(false);
}
#endregion
private void FrmPaymentRecei pt_Load(object sender, System.EventArg s e)
{
this.Visible = false;
this.CalculateB alance();
this.ArticleSal eReturnAmount() ;
string xmlSchema = this.paymentRec eiptDS.GetXml() ;
this.Visible = false;
xmlSchema =
xmlSchema.Repla ce("xmlns=\"htt p://tempuri.org/ReceiptDS.xsd\" ","");
this.Visible = false;
xmlDoc = new XmlDocument();
xmlDoc.LoadXml( xmlSchema);
this.Visible = false;
XmlTextWriter writer =
new XmlTextWriter(" receipt.xml",Sy stem.Text.Encod ing.UTF8);
writer.WriteSta rtDocument(true );
this.Visible = false;
writer.WritePro cessingInstruct ion("xml-stylesheet",
"type=\"tex t/xsl\" href=\"receipt. xsl\"");
writer.WriteRaw (xmlSchema);
writer.Close();
xmlDoc.CreatePr ocessingInstruc tion("xml-stylesheet",
"type=\"tex t/xsl\" href=\"receipt. xsl\"");
this.Visible = false;
this.Initialize Report();
this.Visible = false;
}
private void InitializeRepor t()
{
this.Visible = false;
string strxslName = "receipt.xs l";
if (this.paymentRe ceiptDS.RETURN_ PARTICULARS.Row s.Count<=0)
{
}
else
{
strxslName = "receiptreturn. xsl";
}
StringWriter sw;
sw = MergeXSL_XML("r eceipt.xml",str xslName);
System.IO.Strea mWriter file =
new System.IO.Strea mWriter("receip t.html");
file.WriteLine( sw.ToString());
file.Close();
object empty = System.Reflecti on.Missing.Valu e;
axWebBrowser2.N avigate("about: blank",ref empty,ref empty,
ref empty,ref empty);
mshtml.IHTMLDoc ument2 htmlDoc =
(mshtml.IHTMLDo cument2) axWebBrowser2.D ocument;
htmlDoc.writeln (sw.ToString()) ;
this.Visible = false;
Object a = new object(),b = new object();
if(System.Confi guration.Config urationSettings .AppSettings["ExecutionM ode"]!="Testing")
{
if (printFlag)
{
axWebBrowser2.E xecWB(SHDocVw.O LECMDID.OLECMDI D_PRINT,
SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DONTPROMP TUSER,
ref empty,ref empty );
axWebBrowser2.E xecWB(SHDocVw.O LECMDID.OLECMDI D_PRINT,
SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DONTPROMP TUSER,
ref empty,ref empty );
}
}
this.Visible = false;
}
public StringWriter MergeXSL_XML(st ring xml, string xsl)
{
try
{
//XPathDocument xPath = new XPathDocument(x ml);
XslTransform xTrans = new XslTransform();
xTrans.Load(App lication.Startu pPath+ "\\"+ xsl);
StringWriter strW = new StringWriter();
xTrans.Transfor m(xmlDoc,null,s trW);
strW.Close();
return strW;
}
catch(Exception e)
{
MessageBox.Show (e.ToString());
return null;
}
}