我编写的单元测试失败,并显示以下错误消息。更改单元测试的安全策略
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 switch. Please see http://go.microsoft.com/fwlink/?LinkID=155570 for more information.
链接建议您启用NetFx40_LegacySecurityPolicy,如果你想。我修改了我的单元测试配置,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TestValue" value="true" />
</appSettings>
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>
</configuration>`
但我仍然收到错误消息。我有一个测试,以确保配置文件正在被读取(它测试TestValue
是真的)。另一种可能性,以解决这个问题是要改变项目使用到2.0,而不是4.0的.NET版本,但Visual Studio中说
You cannot change the specified .NET framework version or profile for a test project