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.
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)
Click on Add References in your project and in the .NET Components tab add the System.Web.DataVisualization. This should solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With