kad81
kad81

Reputation: 10950

Designer insisting on 'System.Web.UI.WebControls', which doesn't exist

I've encountered an odd problem: I'm trying to migrate an ASP.NET 4.0 website to an ASP.NET web application. Visual Studio's "Convert to Web Application" function actually worked quite nicely, but the only thing that's not working are the references to charts. I'm getting the error:

The type or namespace name 'Chart' does not exist in the namespace 'System.Web.UI.WebControls'

From the .designer file. The designer is automatically creating this type of code:

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

Based on research I have done, the proper 4.0 namespace to use for charts is System.Web.UI.DataVisualization.Charting. I have added the following components in the web.config (copied from the original website, which was working fine):

<httpHandlers>
    <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<compilation debug="true" targetFramework="4.0">
    <assemblies>
        <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </assemblies>
</compilation>

I can correct the namespaces in the designer files but each time the aspx file is saved, the designer reverts back to the old namespace.

I would love to avoid having to rebuild all of the individual pages from scratch. Is there a setting somewhere that I've missed?

Thanks in advance.

Upvotes: 3

Views: 6443

Answers (1)

kad81
kad81

Reputation: 10950

I was able to solve the problem by adding a few entries to web.config that I had missed. Anyone experiencing this problem needs to make sure you include:

<pages>
    <controls>
        <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </controls>
</pages>

And this (in system.webServer section):

<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>

Upvotes: 1

Related Questions