Jump to content
Software FX Community

Chart FX Crashing - Object reference not set to an instance of an object


sachinj

Recommended Posts

Hi,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

I am using ChartFX 7.0. I am getting a crash when calling the render control method of the chart [Chart1.RenderControl(MyHtmlWriter);]. The chart is created dynamically. The crash does not happens always. It happens only occasionally. When the chart works without crashing I get a license WARNING at the bottom of the chart. But the chart gets displayed. I am running the charts in the different threads to make several charts run in parallel.

 

Please let me know why it is crashing the chart. I am able to replicate a workflow in our application where the crash always happens. It seems like something is not initialized properly inside the ChartFX libraries which gives me the crash.

 

Thanks.

 

Sachin

 

 

Here is the error that I am receiving:

 

Object reference not set to an instance of an object.

at ChartFX.WebForms.Internal.b.a(OutputText A_0, Exception A_1, IServerControl A_2)

at ChartFX.WebForms.Chart.a(Stream A_0, IOutputWriter A_1, OutputText A_2, OutputText A_3, OutputInfo A_4)

at ChartFX.WebForms.Chart.a(OutputText A_0, OutputText A_1, Boolean A_2, String A_3, String A_4)

at ChartFX.WebForms.Chart.Render(HtmlTextWriter writer)

at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)

at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)

at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)

 

 

Here is the sample source code that I am using:

 

using System;

using System.Threading;

using System.IO;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace WebApplication1

{

public partial class TestPage : System.Web.UI.Page

{

string m_Chart = "";protected void Page_Load(object sender, EventArgs e)

{

string chartResponse = "";Thread WorkerThread = new Thread(new ThreadStart(GetNewChart));

WorkerThread.Start();

Thread.Sleep(10000);

Response.Write(m_Chart);

}

public ChartFX.WebForms.Chart GetNewChart(ref string data)

{

ChartFX.WebForms.Chart Chart1 = new ChartFX.WebForms.Chart();

Chart1.ID =

"C" + System.Guid.NewGuid().ToString();Chart1.LegendBox.Visible = false;

Chart1.Gallery = ChartFX.WebForms.

Gallery.Bar;Chart1.AxisX.Title.Text = "Date";Chart1.AxisX.Visible = true;

Chart1.AxisX.LabelAngle = 0;

Chart1.ToolTips =

true;Chart1.Titles.Add(new ChartFX.WebForms.TitleDockable("Workcenter Utilization by Date"));

Chart1.AxisY.Title.Text =

"Utilization (%)";Chart1.AxisY.LabelsFormat.Format = ChartFX.WebForms.AxisFormat.Percentage;

Chart1.AllSeries.PointLabels.Format =

"%v";Chart1.Visible = true;

Chart1.Data.Series = 27;

Random rnd = new Random(12);for (int i = 1; i < 27; i++)

{

for (int col = 1; col < 31; col++)

{

if (col == 1)

{

Chart1.Series[i - 1].Text = "Legend" + i.ToString();

}

Chart1.Data[i - 1, col - 1] = rnd.Next() * 20;

}

}

for (int i = 1; i < 31; i++)

{

Chart1.AxisX.Labels[i - 1] = "08/22/08";

}

 

Chart1.Height = 375;

Chart1.Width = 600;

System.IO.StringWriter MyTextWriter = new System.IO.StringWriter();

System.Web.UI.

HtmlTextWriter MyHtmlWriter = new System.Web.UI.HtmlTextWriter(MyTextWriter);

Chart1.RenderControl(MyHtmlWriter);

//THE CRASH OCCURS ON THIS LINE OF CODE

MyHtmlWriter.Close();

string MyHtml = MyTextWriter.GetStringBuilder().ToString();

data = MyHtml;

return Chart1;

}

public void GetNewChart()

{

GetNewChart(ref m_Chart);

}

}

}

Attached is the warning message related to the license that I receive when chart runs without crashing:

Link to comment
Share on other sites

There are two issues here: 

1) Your license is temporary. When you installed Chart FX you had the option of:

a) Connecting to the internet and obtaining a license

B) Get a challenge code and e-mail it to us to get a license

c) Bypass temporarily.

Seems that you chose option c) but you never obtained a valid license. You need to re-install and obtain a valid license.

2) You are rendering the chart in the PageLoad and that is not correct. What you need to do is to create the chart in the override of CreateChildControls and add it to the Controls collection of your page (instead of calling RenderControl), this way it will enter as part of your control tree, viewstate, etc. and will be rendered at the appropriate time in the page cycle.

Link to comment
Share on other sites

Frank,

 I copied the code from our application in this format where the chart is generated in the Page Load method. I changed the sample code to create the chart in the CreateChildControls function. But the crash happened in that code as well. I don't think the problem is related to Page Life Cylce.

 Another thing I noticed is that this code runs without crashing if I use the VS 2008 built in webserver. This code crashes on the chart render line only when I use IIS with VS 2008 or if I deploy this in IIS. One more thing I found is that it works fine if I call the GetNewChart() functions directly in the Page Load method.

So the crash happens if I create the chart in a new threads and run it under IIS. I think the ChartFX libraries tries to access something for which it doesn't have pemission under IIS?

Can you tell me how get rendering information of chart in difrerent thread running in IIS?

 Thanks.

 Sachin

 

Link to comment
Share on other sites

This is your code:

protected override void CreateChildControls()

{

//GetNewChart(ref m_Chart); //This Function call runs wihout error under IIS

//Response.Write(m_Chart);

//The following function call works well with Visual Studio 2008 in built web server but crashes with IIS

Thread WorkerThread = new Thread(new ThreadStart(GetNewChart)); //When this function is executed under IIS it crashes on the Chart1.RenderControl(MyHtmlWriter) function

WorkerThread.Start();

Thread.Sleep(10000);

Response.Write(m_Chart);

}

You can not create the chart in a separate thread and you don't write to the Respose stream during a CreateChildControls call.

In the CreateChildControls you must do:

m_chart = new Chart();

// Configure chart

....

m_someDiv.Controls.Add(m_chart); // This adds it to the control tree and it will be rendered along with other elements

I don't understand what you are trying to do with this thread. The page cycle is synchronous.

Attached, please find an example application that dynamically creates a chart correctly.

Link to comment
Share on other sites

Hi Frank,

 We were using ChartFX 6.2 in our application which is quite huge and complicated. Recently, we purchased the licenses for the newer version 7.0. When I tried using the charts in our application I got the crash message that I posted. In our application we are creating a number of threads to generate different charts. This used to work fine with version 6.2 but suddenly started crashing with version 7.0. The sample code I posted is my attempt to replicate the problem. It is not exactly how we are doing it in our application. However, the thing that is identical is creating a new thread and calling the renderControl method from IIS. In our UI we are creating a number of charts dynamically and each one is rendered in a different thread which gives me the crash.

What you are implying hat the functionality that we used to have, to be able to render the charts in a different thread is no longer availble in the version 7.0. This would lead us to downgrade our application back to version 6.2.

 Let me know if this a correct assumption.

Thanks.

Sachin

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...