1

I have and extension method for Forms.DataVisualization.Charting.Chart. In the extension method I'm accessing the chartareas array and manipulating the chartarea object in it. However, every time I run my code I get an EntryPointNotFoundException.

//This file is in another assembly and is being reference.
namespace Hetco.Forms
{
    public static class ChartingExtensions
    {
        public static void DoSomething( this Chart chart )
    {
            var c = chart.ChartAreas[0];
            c.Position.X = 0;   // Here I get EntryPointNotFoundException here.
            c.AxisY.ScrollBar.ButtonColor = Color.FromArgb(105, 96, 81);
    }
    }
}

//In another module
private System.Windows.Forms.DataVisualization.Charting.Chart c = new System.Windows.Forms.DataVisualization.Charting.Chart();
c.ChartAreas.Add(somechart);
c.DoSomething();

However, If I added the following code

//In another module
private System.Windows.Forms.DataVisualization.Charting.Chart c = new System.Windows.Forms.DataVisualization.Charting.Chart();
c.ChartAreas.Add(somechart);
var a = c.ChartAreas[0];
a.Position.X = 0;
c.DoSomething();

I don't get the EntryPointNotFoundException but I get a NullReferenceException at

    `c.AxisY.ScrollBar.ButtonColor = Color.FromArgb(105, 96, 81); //in the extension` method.

I can avoid that exception by calling that code before c.DoSomething() but I want to be able to use the extension method. I'm using c# 4.0. I probably forgot to do something but I just don't know what.

Steven
  • 1,143
  • 4
  • 10
  • 15
  • That was really helpful suggesting I debug my code. First, I did. I put break points in the extension method and looked into all the local variable to see if there was anything set to null. I wouldn't have made this much effort to write all that if I hadn't debugged it. – Steven Jan 12 '12 at 18:49
  • Are you referencing the same version of the assembly in both projects (look under references and bring up properties for the reference)? In addition are the namespaces the same for chart in the first project and the second? – Joshua Enfield Jan 12 '12 at 18:58
  • chtMain should be just c. I had to shorten the code. The code does build but fails when run. – Steven Jan 12 '12 at 19:00
  • Both projects are using System.Windows.Forms.DataVisualization.Charting. Both are on framework 4. I created the reference by right clicking the reference node and selecting the first project. – Steven Jan 12 '12 at 19:28

0 Answers0