Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while migrating .NET framework 3.5 to 4.5

Tags:

.net

asp.net

We are migrating our Web applications from .NET framework 3.5 to 4.5

On our development machines, we are using VS2012 and run Windows 7 OS

In this process we got the following error

The base class includes the field 'htmlTag', but its type (System.Web.UI.HtmlControls.HtmlGenericControl) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlElement)

The corresponding HTML is

<html xmlns="http://www.w3.org/1999/xhtml" class="no-js" runat="server" id="htmlTag">

And the corresponding designer code is (.cs.designer file)

protected global::System.Web.UI.HtmlControls.HtmlGenericControl htmlTag;

Full stack trace here..

System.Web.HttpParseException (0x80004005): The base class includes the field 'htmlTag', but its type (System.Web.UI.HtmlControls.HtmlGenericControl) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlElement). at System.Web.Compilation.BaseTemplateCodeDomTreeGenerator.BuildFieldDeclaration(ControlBuilder builder) at System.Web.Compilation.BaseTemplateCodeDomTreeGenerator.BuildSourceDataTreeFromBuilder(ControlBuilder builder, Boolean fInTemplate, Boolean topLevelControlInTemplate, PropertyEntry pse) at System.Web.Compilation.BaseTemplateCodeDomTreeGenerator.BuildSourceDataTreeFromBuilder(ControlBuilder builder, Boolean fInTemplate, Boolean topLevelControlInTemplate, PropertyEntry pse) at System.Web.Compilation.TemplateControlCodeDomTreeGenerator.BuildMiscClassMembers() at System.Web.Compilation.PageCodeDomTreeGenerator.BuildMiscClassMembers() at System.Web.Compilation.BaseCodeDomTreeGenerator.BuildSourceDataTree() at System.Web.Compilation.BaseCodeDomTreeGenerator.GetCodeDomTree(CodeDomProvider codeDomProvider, StringResourceBuilder stringResourceBuilder, VirtualPath virtualPath) at System.Web.Compilation.BaseTemplateBuildProvider.GenerateCode(AssemblyBuilder assemblyBuilder) at System.Web.Compilation.AssemblyBuilder.AddBuildProvider(BuildProvider buildProvider) at System.Web.Compilation.AssemblyBuilder.AddBuildProvider(BuildProvider buildProvider) at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() at System.Web.Compilation.BuildProvidersCompiler.PerformBuild() at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) Error Method: Void AddBuildProvider(System.Web.Compilation.BuildProvider) Help Link:

To fix this issue we followed the steps given at this link http://support.microsoft.com/kb/941824/en-us

In essence we just cut the HTML and paste it back.. and the designer code is regenerated as follows

protected global::System.Web.UI.HtmlControls.HtmlElement htmlTag;

This looks logical way to fix the issue and it also worked on few machines but the same fix broke code on other developer machines and especially code deployed to our production web server too. Please note, we run Windows Server 2008 R2 Datacenter on our production server and we have .Net Framework 4.5 installed on the machine. The following is the error we get after the change

The base class includes the field 'htmlTag' but its type (System.Web.UI.HtmlControls.HtmlElement) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlGenericControl)

You see the error message is just opposite to the first error message in this post

In those machines which now error, if we just leave the type of the control to HTMLGenericControl the error goes away

We tried to compare the .net framework related service packs on the machines that work vs the ones that dont and we really did not notice anything that could possibly cause the error

This situation is unacceptable since we have teams spread across multiple geographic locations and we cannot coordinate with each of them about the way to fix their local environment. More over we cannot check-in this file with changes since it will break for many people and releasing this to production is going to be difficult too

Could you please help us resolve this issue

like image 596
Siva Vaddadi Avatar asked Jul 24 '14 14:07

Siva Vaddadi


1 Answers

At last I found the cause of the issue

Got to admit it was my mistake and an embarrassingly simple fix

By default when target framework for a project is modified to 4.5, it updates the web.config as below

<system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>

First we did not realize VS would modify the web.config when we upgrade to 4.5. Second, our Web.Config is a big file and even if 1 line is modified, it unfortunately shows the entire file as modified. So we never bother to check-in the file to source control unless we explicitly change it by hand. As a result some machines had targetFramework attribute set to 4.5 while others did not have it. This explains the inconsistent behavior across machines. We probably need to format the web.config the way visual studio does when it makes automatic edits and check into source cnotrol to avoid this issue in future

Regards,

Siva

like image 106
Siva Vaddadi Avatar answered Oct 22 '22 01:10

Siva Vaddadi