Adding MSCHART to your Windows azure Web Role and WCF service could cause exception

You might hit an exception while sdding MSCHART to your Windows azure Web Role and WCF service could cause exception as below:

  1. Create a new Windows Azure ASP.NET Webrole
  2. Add a new WCF Web Role to it
  3. Build and verify that it does works in Compute Emulator
  4. Add MsChart control on any ASP page within your Web Role
  5. Verify that web.config is updated with mschart control specific configuration
  6. Build and run it again in Compute Emulator

You will hit an exception as below:

To solve this problem you just need to add the following in your web.config inside system.webserver section:

<validation validateIntegratedModeConfiguration="false"/>

The final system.webserver looks like as below:

 <system.webServer>
 <modules runAllManagedModulesForAllRequests="true" />
 <handlers>
 <remove name="ChartImageHandler" />
 <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
 path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
 </handlers>
 <validation validateIntegratedModeConfiguration="false"/>
 </system.webServer>