将.NET Framework 3.5迁移到4.5时出错 [英] Error while migrating .NET framework 3.5 to 4.5

查看:69
本文介绍了将.NET Framework 3.5迁移到4.5时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将Web应用程序从.NET Framework 3.5迁移到4.5

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

在我们的开发机器上,我们正在使用VS2012并运行Windows 7 OS

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

在此过程中,出现以下错误

In this process we got the following error

基类包含字段"htmlTag",但其类型(System.Web.UI.HtmlControls.HtmlGenericControl)与控件的类型(System.Web.UI.HtmlControls.HtmlElement)不兼容

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)

相应的HTML是

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

相应的设计者代码是(.cs.designer文件)

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):基类包含字段"htmlTag",但其类型(System.Web.UI.HtmlControls.HtmlGenericControl)与控件的类型(System.Web.UI)不兼容.HtmlControls.HtmlElement).在System.Web.Compilation.BaseTemplateCodeDomTreeGenerator.BuildFieldDeclaration(ControlBuilder builder)处System.Web.Compilation.BaseTemplateCodeDomTreeGenerator.BuildSourceDataTreeFromBuilder(ControlBuilder builder,Boolean fInTemplate,Boolean topLevelControlInTemplate,PropertyEntry pse)在System.Web.Compilation.BaseTemplateBuilderFromBuilderBuilder,System.Web.Compilation.TemplateControlCodeDomTreeGenerator.BuildMiscClassMembers()(位于System.Web.Compilation.PageCodeDomTreeGenerator.BuildMiscClassMembers()在System.Web.Compilation.BaseCodeDomTreeGenerator.BuildSourceWebTree()处的Boolean fInTemplate,布尔topLevelControlInTemplate,PropertyEntry pse)..Compilation.BaseCodeDomTreeGenerator.GetCodeDomTree(CodeDomProvider codeDomProvider,System.Web.Compilation.BaseTemplateBuildProvider.GenerateCode(AssemblyBuilder assemblyBuilder)处的System.Web.Compilation.BaseTemplateBuildProvider.GenerateCode(AssemblyBuilder assemblyBuilder)System的System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()的System.Web.Compilation.AssemblyBuilder.AddBuildProvider(BuildProvider的BuildProvider)的System.Web.Compilation.BuildProvidersCompiler.PerformBuild()的mpilation.AssemblyBuilder.AddBuildProvider(BuildProvider的BuildProvider).System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath,布尔值noBuild,布尔值allowCrossApp,布尔值allowBuildInPrecompile,布尔值(HttpContext上下文,VirtualPath,VirtualPath,布尔noBuild,布尔allowCrossApp,布尔allowBuildInPrecompile,布尔throwIfNotFound,布尔sureIsUpToDate)位于Syste,位于System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath虚拟路径,HttpContext上下文,布尔allowCrossApp,布尔throwIfNotFound)System.Web上的m.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath,Type requiredBaseType,HttpContext context,Boolean allowCrossApp)在System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context,String requestType,VirtualPath virtualPath,String physicalPath).System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,Boolean&上的HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute().错误完成方法:无效AddBuildProvider(System.Web.Compilation.BuildProvider)帮助链接:

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:

为解决此问题,我们按照此链接 http://support上给出的步骤进行操作.microsoft.com/kb/941824/en-us

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

实质上,我们只是剪切HTML并将其粘贴回..,然后按如下所示重新生成设计器代码

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;

这看起来很合乎逻辑,可以解决此问题,并且在少数机器上也可以使用,但是相同的修正破坏了其他开发人员机器上的代码,尤其是部署到我们的生产Web服务器上的代码.请注意,我们在生产服务器上运行Windows Server 2008 R2数据中心,并且在计算机上安装了.Net Framework 4.5.以下是更改后我们得到的错误

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

基类包含字段"htmlTag",但其类型(System.Web.UI.HtmlControls.HtmlElement)与控件的类型(System.Web.UI.HtmlControls.HtmlGenericControl)不兼容

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

在那些现在出错的机器中,如果我们只是将控件的类型留给 HTMLGenericControl ,错误就会消失

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

我们试图比较可以正常运行的计算机与不正常运行的计算机上与.net框架相关的服务包,我们确实没有发现任何可能导致错误的东西

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

推荐答案

最后我找到了问题的原因

At last I found the cause of the issue

必须承认这是我的错误,也是一个尴尬的简单修复程序

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

默认情况下,将项目的目标框架修改为4.5时,它将如下更新web.config

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>

首先,我们没有意识到当升级到4.5时VS会修改web.config.其次,我们的Web.Config是一个大文件,即使修改了1行,不幸的是,它也会显示整个文件.因此,除非我们手动进行明确更改,否则我们永远不会费心将文件检入到源代码管理中.结果,有些机器将targetFramework属性设置为4.5,而其他机器则没有.这解释了机器之间的不一致行为.我们可能需要像Visual Studio进行自动编辑时一样格式化web.config,并检查源cnotrol以避免将来出现此问题

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

此致

Siva

这篇关于将.NET Framework 3.5迁移到4.5时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆