We're getting following exception for the below piece of code. We're
wondering how it is possible since we're having a null check for
objGraphics and strokePen...
Exception: System.NullReferenceException: Object reference not set to an
instance of an object
if (strokePen != null && objGraphics != null)
{
if (float.Parse(style["x1"])>=0 && float.Parse(style["y1"])>= 0 &&
float.Parse(style["x2"])>=0 && float.Parse(style["y2"])>=0 )
{
objGraphics.DrawLine(strokePen,
float.Parse(style["x1"]),
float.Parse(style["y1"]),
float.Parse(style["x2"]),
float.Parse(style["y2"]));
}
}
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.] System.Drawing.SafeNativeMethods.GdipDrawLine(HandleRef
graphics, HandleRef pen, Single x1, Single y1, Single x2, Single y2) +0
System.Drawing.Graphics.DrawLine(Pen pen, Single x1, Single y1, Single
x2, Single y2) +121
Thomson.Financial.Thomlets.Datastream.Web.Core.SVGImage.Render(Graphics&
objGraphics, XmlNode containerNode) in
d:\economics\src\economics\datastream.web.core\svg\svgrenderer.cs:372
Thomson.Financial.Thomlets.Datastream.Web.Core.SVGImage.RenderSVG(Graphics&
objGraphics, Int32 width, Int32 height) in
d:\economics\src\economics\datastream.web.core\svg\svgrenderer.cs:178
Thomson.Financial.Thomlets.Datastream.Web.Core.SVGImage.Render(Int32
width, Int32 height) in
d:\economics\src\economics\datastream.web.core\svg\svgrenderer.cs:148
Thomson.Financial.Thomlets.Datastream.Web.Core.PngRenderStream.Flush() in
d:\economics\src\economics\datastream.web.core\svg\pngrenderstream.cs:73
System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
+169 System.IO.StreamWriter.Flush() +12
System.Xml.XmlTextWriter.Flush() +7 System.Xml.XmlDocument.Save(Stream
outStream) +76
Thomson.Financial.Thomlets.Datastream.Web.Core.ChartWriter.WritePngChart(XmlDocument
chartXml, SimpleHttpResponse httpResponse, Int32 width, Int32 height) in
d:\economics\src\economics\datastream.web.core\charting\chartwriter.cs:49
Thomson.Financial.Thomlets.Economics.Web.LineChartPNGRequest.GenerateChart()
in
d:\economics\src\economics\economics.web\linechartpngrequest.aspx.cs:87
Thomson.Financial.Thomlets.Economics.Web.LineChartPNGRequest.OnLoad(EventArgs
e) in
d:\economics\src\economics\economics.web\linechartpngrequest.aspx.cs:55
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
ASP.NET Version:1.1.4322.2032
------=_NextPart_000_0008_01C6B66C.7CF39820
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-Google-AttachSize: 9218
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2912" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">We're getting following
exception for the below piece of code. We're wondering how it is possible
since
we're having a null check for objGraphics and strokePen...</SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><?xml:namespace prefix = o ns
=
"urn:schemas-microsoft-com
ffice
ffice" /><o
> </o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o
></o
></SPAN> </P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Exception: </SPAN><SPAN
style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY:
Arial">System.NullReferenceException:
Object reference not set to an instance of an
object<o
></o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY:
Arial"><o
> </o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier
New'">if</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> (strokePen != <SPAN
style="COLOR: blue">null</SPAN> && objGraphics != <SPAN
style="COLOR: blue">null</SPAN>)<o
></o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier
New'">{<o
></o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-INDENT: 0.5in"><SPAN
style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier
New'">if</SPAN><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"> (<SPAN
style="COLOR: blue">float</SPAN>.Parse(style["x1"])>=0 &&
<SPAN
style="COLOR: blue">float</SPAN>.Parse(style["y1"])>= 0 &&
<SPAN
style="COLOR: blue">float</SPAN>.Parse(style["x2"])>=0 &&
<SPAN
style="COLOR: blue">float</SPAN>.Parse(style["y2"])>=0
)<o
></o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier
New'">
{<o
></o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier
New'"><EM><STRONG>
objGraphics.DrawLine(strokePen,<o
></o
></STRONG></EM></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier
New'">
<SPAN style="COLOR:
blue">float</SPAN>.Parse(style["x1"]),<o
></o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier
New'">
<SPAN style="COLOR:
blue">float</SPAN>.Parse(style["y1"]),<o
></o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier
New'">
<SPAN style="COLOR:
blue">float</SPAN>.Parse(style["x2"]),<o
></o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier
New'">
<SPAN
style="COLOR:
blue">float</SPAN>.Parse(style["y2"]));<o
></o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier
New'">
}<o
></o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier
New'">}<o
></o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier
New'"><o
> </o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Stack
Trace:<o
></o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier
New'"><o
> </o
></SPAN></P><PRE><SPAN style="FONT-SIZE: 9pt;
COLOR: black"><FONT face="Lucida Console">[NullReferenceException: Object
reference not set to an instance of an
object.]<o
></o
></FONT></SPAN></PRE><PRE><SPAN style="FONT-SIZE: 9pt;
COLOR: black"><FONT face="Lucida Console">
System.Drawing.SafeNativeMethods.GdipDrawLine(HandleRef graphics,
HandleRef pen, Single x1, Single y1, Single x2, Single y2)
+0<o
></o
></FONT></SPAN></PRE><PRE><SPAN style="FONT-SIZE: 9pt; COLOR:
black"><FONT face="Lucida Console">
System.Drawing.Graphics.DrawLine(Pen pen, Single x1, Single y1, Single
x2, Single y2) +121<o
></o
></FONT></SPAN></PRE><PRE><SPAN
style="FONT-SIZE: 9pt; COLOR: black"><FONT face="Lucida
Console">
Thomson.Financial.Thomlets.Datastream.Web.Core.SVGImage.Render(Graphics&
objGraphics, XmlNode containerNode) in
d:\economics\src\economics\datastream.web.core\svg\svgrenderer.cs:372<o
></o
></FONT></SPAN></PRE><PRE><SPAN
style="FONT-SIZE: 9pt; COLOR: black"><FONT face="Lucida
Console">
Thomson.Financial.Thomlets.Datastream.Web.Core.SVGImage.RenderSVG(Graphics&
objGraphics, Int32 width, Int32 height) in
d:\economics\src\economics\datastream.web.core\svg\svgrenderer.cs:178<o
></o
></FONT></SPAN></PRE><PRE><SPAN
style="FONT-SIZE: 9pt; COLOR: black"><FONT face="Lucida
Console">
Thomson.Financial.Thomlets.Datastream.Web.Core.SVGImage.Render(Int32
width, Int32 height) in
d:\economics\src\economics\datastream.web.core\svg\svgrenderer.cs:148<o
></o
></FONT></SPAN></PRE><PRE><SPAN
style="FONT-SIZE: 9pt; COLOR: black"><FONT face="Lucida
Console">
Thomson.Financial.Thomlets.Datastream.Web.Core.PngRenderStream.Flush() in
d:\economics\src\economics\datastream.web.core\svg\pngrenderstream.cs:73<o
></o
></FONT></SPAN></PRE><PRE><SPAN
style="FONT-SIZE: 9pt; COLOR: black"><FONT face="Lucida
Console"> System.IO.StreamWriter.Flush(Boolean flushStream,
Boolean flushEncoder) +169<o
></o
></FONT></SPAN></PRE><PRE><SPAN
style="FONT-SIZE: 9pt; COLOR: black"><FONT face="Lucida
Console"> System.IO.StreamWriter.Flush()
+12<o
></o
></FONT></SPAN></PRE><PRE><SPAN style="FONT-SIZE: 9pt;
COLOR: black"><FONT face="Lucida Console">
System.Xml.XmlTextWriter.Flush()
+7<o
></o
></FONT></SPAN></PRE><PRE><SPAN style="FONT-SIZE: 9pt; COLOR:
black"><FONT face="Lucida Console">
System.Xml.XmlDocument.Save(Stream outStream)
+76<o
></o
></FONT></SPAN></PRE><PRE><SPAN style="FONT-SIZE: 9pt;
COLOR: black"><FONT face="Lucida Console">
Thomson.Financial.Thomlets.Datastream.Web.Core.ChartWriter.WritePngChart(XmlDocument
chartXml, SimpleHttpResponse httpResponse, Int32 width, Int32 height) in
d:\economics\src\economics\datastream.web.core\charting\chartwriter.cs:49<o
></o
></FONT></SPAN></PRE><PRE><SPAN
style="FONT-SIZE: 9pt; COLOR: black"><FONT face="Lucida
Console">
Thomson.Financial.Thomlets.Economics.Web.LineChartPNGRequest.GenerateChart()
in
d:\economics\src\economics\economics.web\linechartpngrequest.aspx.cs:87<o
></o
></FONT></SPAN></PRE><PRE><SPAN
style="FONT-SIZE: 9pt; COLOR: black"><FONT face="Lucida
Console">
Thomson.Financial.Thomlets.Economics.Web.LineChartPNGRequest.OnLoad(EventArgs
e) in
d:\economics\src\economics\economics.web\linechartpngrequest.aspx.cs:55<o
></o
></FONT></SPAN></PRE><PRE><SPAN
style="FONT-SIZE: 9pt; COLOR: black"><FONT face="Lucida
Console"> System.Web.UI.Control.LoadRecursive()
+35<o
></o
></FONT></SPAN></PRE><PRE><SPAN style="FONT-SIZE: 9pt;
COLOR: black"><FONT face="Lucida Console">
System.Web.UI.Page.ProcessRequestMain()
+750<o
></o
></FONT></SPAN></PRE>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier
New'"><o
> </o
></SPAN></P>
<P class=MsoNormal style="MARGIN: 0in 0in 0pt"><B><SPAN
style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY: Verdana">Version
Information:</SPAN></B><SPAN
style="FONT-SIZE: 8.5pt; COLOR: black; FONT-FAMILY:
Arial"> Microsoft .NET
Framework Version:1.1.4322.2032; ASP.NET
Version:1.1.4322.2032</SPAN><o
></o
></P>
<P class=MsoNormal
style="MARGIN: 0in 0in 0pt"><o
> </o
></P></DIV></BODY></HTML>
------=_NextPart_000_0008_01C6B66C.7CF39820--