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/开发者_如何学Go?LinkID=155570 for more information.
The link recommends you enable the NetFx40_LegacySecurityPolicy if you want to . 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). 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
You cannot change the specified .NET framework version or profile for a test project
Unit tests are run by C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\QtAgent32.exe so adding the flag to QtAgent32.exe.config fixed the issue.
精彩评论