Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 with .NET 4.0 not recognising System.Web.UI.DataVisualization.Charting

I am using Visual Studio 2010 with .NET 4.0.

I have just started using the MS charting. When I complie the project, I get following error:

The type or namespace name 'DataVisualization' does not exist in the namespace 'System.Web.UI' (are you missing an assembly reference?)

And also, in my code, this line has a squigly line underneath it indicating that the namespace cannot be found:

using System.Web.UI.DataVisualization.Charting;

However, if I go to my localhost to the page that has the chart in it, it renders fine.

The other strange thing is that when I compile (CTRL + SHIFT + B), I will get 3 compilation errors the first time I compile, then when I do it again, straight after, I get 16.

Even though I get the compilation errors above, I can still run the application and everything works fine, but it is really annoying that it won't compile so I must be doing something wrong.

Any help with this would be much appreciated.

Thanks.

like image 736
domaa Avatar asked Dec 07 '22 18:12

domaa


2 Answers

Ok, figured out the problem.

I looked on Google ... StackOverflow and found this page, but I knew that the problem was not needing to be fixed by starting over.

I have ALL the references and fixed up web.config, and I still got the error.

Answer is to change the .Designer code from

protected global::System.Web.UI.WebControls.Chart chartDailyVolume;

to

protected global::System.Web.UI.DataVisualization.Charting.Chart chartDailyVolume;

I had copied and pasted code from another visual studio 2010 project to the page and the designer actually bound it wrong. When I dragged another Chart to the page and then removed it and compiled fine, I compared my checked in code from TFS to the new fix. Thus I noticed that the Designer.cs actually generated it wrong from a copy and paste even though both were visual studio 2010 solution projects (both with Target Framework of .NET Framework 4)

like image 113
Tom Stickel Avatar answered May 14 '23 14:05

Tom Stickel


Click on Add References in your project and in the .NET Components tab add the System.Web.DataVisualization. This should solve your problem.

like image 22
Anand Satyan Avatar answered May 14 '23 13:05

Anand Satyan