简体   繁体   English

更改单元测试的安全策略

[英]Changing the security policy for a unit test

A unit test I've written is failing with the following error message. 我编写的单元测试失败,并显示以下错误消息。

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.

The link recommends you enable the NetFx40_LegacySecurityPolicy if you want to . 如果需要,该链接建议您启用NetFx40_LegacySecurityPolicy。 I've modified my Unit test config as below: 我已经修改了我的单元测试配置,如下所示:

 <?xml version="1.0" encoding="utf-8" ?>
   <configuration>
     <appSettings>
       <add key="TestValue" value="true" />
     </appSettings>
   <runtime>
     <NetFx40_LegacySecurityPolicy enabled="true"/>
   </runtime>
 </configuration>`

But I still receive the error message. 但是我仍然收到错误消息。 I have a test above it to ensure the config file is being read (it tests TestValue is true). 我上面有一个测试,以确保配置文件被读取(它测试TestValue为true)。 The other possibility to fix this is to change the .NET version the project is using to 2.0 rather than 4.0 but Visual Studio says 解决此问题的另一种可能性是将项目使用的.NET版本更改为2.0而不是4.0,但Visual Studio说

You cannot change the specified .NET framework version or profile for a test project

单元测试由C:\\ Program Files \\ Microsoft Visual Studio 10.0 \\ Common7 \\ IDE \\ QtAgent32.exe运行,因此将标志添加到QtAgent32.exe.config可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM