# .NET and More > WPF, WCF, WF >  [RESOLVED] Object reference not set to an instance of an object.

## trevorjeaton

Hi all,

here's one for you:

I download and install the WPF toolkit for Feb 2010 that has the chart control in it, i add a reference to that chart control in my app, then I create a window and drag a chart control on to it - it defaults to a name of chart1.

if i call that window i get an "Object reference not set to an instance of an object." error - in my case i'm trying to drag a column chart on to the window.

Any thoughts?

----------


## chris128

What do you mean by "if I call that window" ... Are you saying this exception is thrown as soon as you show the window or what? Also is this in the designer or when you actually launch the program?

----------


## trevorjeaton

correct - when i show the window from my main window:



```

dim f2 as new window1
f2.show()
```

if i delete the chart, the window loads fine.  It happens in both an F5 build or CTRL-F5 build....i can see and work with the chart on the window in design mode no problem, can also access the xaml and codebehind - i'm trying to use a datatable as a data source for a column chart - at first i thought it was the format of the data table that was the problem but eventually in going through the process of elimination i finally decided to create a blank form and just drop a chart control on it and see what happens and it still errored out.

----------


## chris128

Wrap the call in a Try/Catch and post the full stack trace here, i.e:


vb Code:
Try
   Dim f2 As New Window1
   f2.Show()
Catch ex As Exception
   SomeTextBox.Text = ex.ToString 'Now copy the text that is placed in SomeTextBox and post it here
End Try

----------


## trevorjeaton

okay done:



```

System.NullReferenceException: Object reference not set to an instance of an object.
```

Further info is that my dev machine is 64 bit windows 7 - would that affect the added on wpf toolkit and its install location?  I may have run across that in one of my previous posts but will have to check them - will post my findings on that as well.

----------


## trevorjeaton

the 64 bit issue was with RIA services, so nevermind on that one, but the chart issue remains...

can you duplicate it?  my order of operations was this:

 - install the wpf toolkit
 - create a new project
 - add a reference to the wpftoolkit.dll to your project
 - drop a button on to the main form
 - add a new window to the project called window1
 - drag a chart control on to that window
 - in the codebehind on the button on the main window add this:



```

dim f2 as new window1
f2.show
```

press f5 to build, then click the button on the main form to see if it launches window1 with a blank chart.  If successfull, then i may have to take a look at my visual studio installation.  also, as stated above, the dev machine is 64 bit win 7 ultimate and VS 2010

----------


## chris128

> okay done:
> 
> 
> 
> ```
> 
> System.NullReferenceException: Object reference not set to an instance of an object.
> ```
> 
> Further info is that my dev machine is 64 bit windows 7 - would that affect the added on wpf toolkit and its install location?  I may have run across that in one of my previous posts but will have to check them - will post my findings on that as well.


There should be much more info than that - you might need to make sure whatever textbox you made it output to is able to hold more than one line (cant remember if the WPF textbox has a multiline property like the winforms one does). The kind of output I'm looking for is what you see in the bottom textbox in this image:

----------


## trevorjeaton

yep, i know exactly what you're talking about, and was what i was expecting to see too, hence my head scratching on this one - will try a textblock instead of a textbox.

----------


## trevorjeaton

textblock did the trick:



```

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Controls.DataVisualization.Charting.ColumnSeries.<>c__DisplayClass8.<GetAxes>b__4() in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\Charting\Series\ColumnSeries.cs:line 47
   at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.GetAxes(DataPoint firstDataPoint, Func`2 independentAxisPredicate, Func`1 independentAxisFactory, Func`2 dependentAxisPredicate, Func`1 dependentAxisFactory) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\Charting\Series\DataPointSeriesWithAxes.cs:line 482
   at System.Windows.Controls.DataVisualization.Charting.ColumnSeries.GetAxes(DataPoint firstDataPoint) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\Charting\Series\ColumnSeries.cs:line 35
   at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.GetAxes() in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\Charting\Series\DataPointSeriesWithAxes.cs:line 394
   at System.Windows.Controls.DataVisualization.Charting.DataPointSeriesWithAxes.OnDataPointsChanged(IList`1 newDataPoints, IList`1 oldDataPoints) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\Charting\Series\DataPointSeriesWithAxes.cs:line 319
   at System.Windows.Controls.DataVisualization.Charting.DataPointSingleSeriesWithAxes.OnDataPointsChanged(IList`1 newDataPoints, IList`1 oldDataPoints) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\Charting\Series\DataPointSingleSeriesWithAxes.cs:line 277
```

interesting - looks like a bug - the references to the .cs extesions is what caught my eye - this app is vb 2010 lol - and i have no folder in the root of my C: named 'dd'

Going to download the toolkit and install it again......weird......

----------


## trevorjeaton

same issue with a newly installed wpf toolkit - one thing i am noticing is that the toolkit is version 3.5.50211.1 - would it be safe to assume it targets the .net 3.5 framework?  my app specifically targets 4.0

----------


## trevorjeaton

okay, also, i just finished changing my target framework and recompiling each time from the 4.0 client profile to the 4.0 full framework and then in turn to the 3.5 client profile, and finally the 3.5 full framework - same error as above on all targeted frameworks with a freshly installed wpf toolkit (feb 2010 version)
.

----------


## techgnome

"System.Windows.Controls" < -- Umm.... is the chart control a WPF control? Or a WinForms control? .... I know it's possible to use WPF controls in a WinForm app with the appropriate container... but I'm not sure it works the other way around.

-tg

----------


## trevorjeaton

the wpf toolkit (from what i'm reading about it anyway) is a 100&#37; wpf control for the chart

here's the link - looks like charts are still in the preview quality band though:

http://wpf.codeplex.com/releases/view/40535

----------


## chris128

> "System.Windows.Controls" < -- Umm.... is the chart control a WPF control? Or a WinForms control? .... I know it's possible to use WPF controls in a WinForm app with the appropriate container... but I'm not sure it works the other way around.
> 
> -tg


System.Windows.Controls is a WPF namespace... I think you might have misread it and seen System.Windows.Forms  :Wink: 

Trevorjeaton - if I get chance tonight I'll try installing it and see if I have the same problem

----------


## trevorjeaton

its just trev by the way guys :-)

Thanks for the assistance - its highly appreciated.

----------


## chris128

Just tried and I get the same problem and also the very first time I tried it I got prompted to select the location of DataPointSeries.cs... on subsequent runs I get the same thing you get in the stack trace where it is looking for 'C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataVisualization\Charting\Series\DataPointSeries.c  s'

I know its in the Preview quality band (which they say is equivalent to Alpha stage) but you would at least expect the thing to actually be able to be displayed on a form! I've never been very impressed with anything in the WPF Toolkit to be honest, I see lots of people reporting lots of bugs and it looks like MS dont put that much effort into it really. I'd rather just wait until controls make it into the official versions of the framework, which hopefully the Chart control will in the next version... but thats not much use to you right now. I'm afraid you might have to just shell out for a third party charting component or try and build your own. I know at work some of our developers use the DevExpress controls but I've no experience with them myself so cant say how good they are - they have a WPF charting control here: http://www.devexpress.com/Products/N.../WPF/Charting/

----------


## trevorjeaton

okay, thanks for the confirmation - i guess patience is a virtue and i'll hurry up and wait on this one....

----------

