locked
Error while migrating .NET framework 3.5 to 4.5 RRS feed

  • Question

  • User226270325 posted

    Hi,

    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 (once we built the solution with this change and dropped the dlls to local webserver, the website started working) 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

    Thanks,

    Siva

    Friday, July 25, 2014 2:21 AM

Answers

  • User-166373564 posted

    Hi Siva,

    First you need check whether your .net 3.5 asp.net application works fine on your side, and then follow the procedure below.

    Here is step by step instructions for upgrade ASP.NET app to 4.0, it involves describes tasks, resources, and issues related to migrating applications from the .NET Framework 3.5 to the .NET Framework 4.

    Upgrade an ASP.NET Web Application to ASP.NET 4: http://msdn.microsoft.com/en-us/library/vstudio/dd483478(v=vs.100).aspx

    Migration guide: http://msdn.microsoft.com/en-us/library/vstudio/ff657133(v=vs.100).aspx

    Regards

    Angie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 28, 2014 2:24 AM
  • User-166373564 posted

    Hi Siva,

    Also the behavior is not consistent, it works on few machines and doesnt on others

    Sorry for the issue that you are hitting. For this issue, I'd like to suggest you to give a feedback to Microsoft Connect Site, and check whether they have good workaround for you, Microsoft engineers will evaluate this seriously.

    Visual Studio Connect Site: https://connect.microsoft.com/visualstudio 

    Regards

    Angie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 31, 2014 11:09 PM

All replies

  • User-166373564 posted

    Hi Siva,

    First you need check whether your .net 3.5 asp.net application works fine on your side, and then follow the procedure below.

    Here is step by step instructions for upgrade ASP.NET app to 4.0, it involves describes tasks, resources, and issues related to migrating applications from the .NET Framework 3.5 to the .NET Framework 4.

    Upgrade an ASP.NET Web Application to ASP.NET 4: http://msdn.microsoft.com/en-us/library/vstudio/dd483478(v=vs.100).aspx

    Migration guide: http://msdn.microsoft.com/en-us/library/vstudio/ff657133(v=vs.100).aspx

    Regards

    Angie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 28, 2014 2:24 AM
  • User226270325 posted

    Hi Angie,

    The problem we are having is migration to .NET 4.5 and not .NET 4.0

    After the migration everything works except for the designer file changes as mentioned in my post 

    Also the behavior is not consistent, it works on few machines and doesnt on others

    I followed all the steps given in your link and still get the same error 

    Thanks,

    Siva

    Tuesday, July 29, 2014 3:42 AM
  • User-166373564 posted

    Hi Siva,

    Thanks for your feedback.

    For this issue, please try to recompile the code using the .net 4.5 runtime. And when doing this, you need to change the *.designer.cs file reference from:

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

    To

    protected global::System.Web.UI.HtmlControls.HtmlElement html.

    Further information:  http://forums.asp.net/t/1979255.aspx 

    If you have any concern, please let me know.

    Regards

    Angie

    Wednesday, July 30, 2014 11:08 PM
  • User226270325 posted

    Hi Angie,

    We did check the link you mentioned before posting the question here

    We did recompile the code after changing the target framework to .NET 4.5 in visual studio

    After recompiling only we got the dlls that we copied to our production environment and it breaks

    Also as mentioned in my original post the same issue happens on some of the developer machines too, there also we are recompiling

    Do you have any suggestions to fix this

    Thanks,

    Siva

    Thursday, July 31, 2014 7:39 AM
  • User-166373564 posted

    Hi Siva,

    Also the behavior is not consistent, it works on few machines and doesnt on others

    Sorry for the issue that you are hitting. For this issue, I'd like to suggest you to give a feedback to Microsoft Connect Site, and check whether they have good workaround for you, Microsoft engineers will evaluate this seriously.

    Visual Studio Connect Site: https://connect.microsoft.com/visualstudio 

    Regards

    Angie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 31, 2014 11:09 PM
  • User226270325 posted

    Hi Angie,

    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

    Thanks for your support and answers

    Regards,

    Siva

    Friday, August 8, 2014 12:59 AM