VS2010中打开项目中的Winform界面报“This method explicitly users CAS policy,which has been obsoleted...”(续)

问题描述

  上一篇文章《VS2010中打开项目中的Winform界面报“This method explicitly users CAS policy,which has been obsoleted by the …”》中介绍了程序从.net framework3.5升级到4.0之后,在VS2010中打不开界面设计器,后来通过在devenv.exe.config文件的runtime标签下增加了一行<NetFx40_LegacySecurityPolicy enabled=“true”/>子标签解决的问题。
  本以为可以安心的写代码了,但是事与愿违,编译解决方案的时候又爆出了一堆错误。整理了一下错误,总共有以下几类错误,如下所示,都是在编译解决方案过程中报的错误:

1)The “GenerateResource” task failed unexpectedly.
System.InvalidOperationException:The security state of an AppDomain was modified by an AppDomainManager configured with the NoSecurityChanges flag.
2)The “ResolveComReference” task could not be instantiated from “Microsoft.Build.Tasks.v4.0,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”.The security state of an AppDomain was modified by an AppDomainManager configured with the NoSecurityChanges flag.
3)The “ResolveComReference” task has been declared or used incorrectly,or failed during construction.Check the spelling of the task name and the assembly name.
4)the “CompileWorkflowTask” task failed unexpectedly.
System.InvalidOperationException:The security state of an AppDomain was modified by an AppDomainManager configured with the NoSecurityChanges flag.
5)The “UnregisterAssembly” task could not be instantiated from “Microsoft.Build.Tasks.v4.0,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”.The security state of an AppDomain was modified by an AppDomainManager configured with the NoSecurityChanges flag.
6)The “UnregisterAssembly” task has been declared or used incorrectly,or failed during construction.Check the spelling of the task name and the assembly name.

解决方案

  编译不成功的来源就是在devenv.exe.config文件中增加了那项配置,测试了一下,如果将该项去掉,然后重启VS2010就能正常的编译解决方案,但这时VS2010中的界面设计器又打不开了。重新在devenv.exe.config文件中增加了相应配置,VS2010中的界面设计器可以打开,但是解决方案又编译不通过了。
  百度一些资料,要么说要修改mBuild程序配置文件中的设置,要么就是一些其它方法。先是测试了参考文献1中的方法,不过对我的问题不适用。后来又试过安装VS2010 SP1的补丁,也没有用。
  后来抱着“解决不了问题就解决出问题的代码”的心态,查找程序中的出错代码,通过报错位置及调用堆栈,最终定位到应该是程序中的使用的DX12中的SimpleButton和CheckButton控件抛的异常。进一步进行测试,在一个普通的winform窗口中,从VS2010的工具条中拖SimpleButton或CheckButton控件到winform界面,都会报以下错误:

"System.TypeInitializationException:The type initializer for ‘DevExpress.Utils.Design.BaseControlDesigner’ threw an exception.—>System.NotSupportedException:This method explicitly uses CAS policy,which has been obsoleted by the .NET Framework.In order to enable CAS policy for compatibility reasons,please use the NetFx40_LegacySecurityPolicy configuration swithch.Please see http://go.microsoft.com.fwlink/?LinkID=155570 for more information.

  结合上述分析,能确定就是之前代码中使用的SimpleButton或CheckButton控件升级到.net framework 4.0后在VS2010中打开时报的错,导致VS2010的界面设计器打不开,打开的时候就报上面的错误。
  将代码中的SimpleButton和CheckButton控件改为VS2010自带控件,再重新编译解决方案,即可成功编译,连带上一篇文章的问题也解决了。

参考文献:
[1]GenerateResource”任务意外失败的解决方法,https://blog.csdn.net/ZZTT18248/article/details/101445596?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.control

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值