1
Vote

CAS Policy issue on .NET 4.0

description

During edxecution of a unit test using the VS2010 SP1 unit test framework, the following error occurred:
 
Error Message:
Test method <removed>Fixture.TestBase threw exception:
System.NotSupportedException: This method implicitly 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.
 
Stack trace:
System.Reflection.Assembly.Load(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence securityEvidence)
Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
Microsoft.CSharp.CSharpCodeGenerator.FromDomBatch(CompilerParameters options, CodeCompileUnit[] ea)
Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromDomBatch(CompilerParameters options, CodeCompileUnit[] ea)
System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromDom(CompilerParameters options, CodeCompileUnit[] compilationUnits)
System.Xml.Xsl.XsltOld.Compiler.CompileAssembly(ScriptingLanguage lang, Hashtable typeDecls, String nsName, Evidence evidence)
System.Xml.Xsl.XsltOld.Compiler.CompileScript(Evidence evidence)
System.Xml.Xsl.XsltOld.Compiler.Compile(NavigatorInput input, XmlResolver xmlResolver, Evidence evidence)
System.Xml.Xsl.XslTransform.Compile(XPathNavigator stylesheet, XmlResolver resolver, Evidence evidence)
System.Xml.Xsl.XslTransform.Load(XPathNavigator stylesheet, XmlResolver resolver, Evidence evidence)
System.Xml.Xsl.XslTransform.Load(IXPathNavigable stylesheet, XmlResolver resolver, Evidence evidence)
MapTestFramework.Common.TransformBaseMapExecuter.get_Transformer()
MapTestFramework.Common.TransformBaseMapExecuter.ExecuteMap(String sourcePath, String targetPath)
MapTestFramework.Common.TestHelper.TestMap(String testName, String sourcePath, String actualPath, String expectedPath)
MapTestFramework.Common.TestHelper.TestMap(String name)
MapTestFramework.Common.MappingFixture.ExecuteBaseTest()
<removed>.TestBase() in <removed>Fixture.cs: line 31
 
I tried adding an App.config to the test project with the following:
 
<configuration>
<runtime>
  <NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>
</configuration>
 
But that didn't work. I also tried adjusting the devenv.exe.config with the NetFx40_LegacySecurityPolicy setting (a solution I really didn't like), but that resulted in many security related issues while compiling the BizTalk solution.
 
Any suggestions?

comments

pbvs wrote May 12, 2015 at 1:28 PM

I ran into the same issue and solved it by adding a app.config file with the the following configuration:

<configuration>
<runtime>
  <legacyCasPolicy enabled="true" />
</runtime>
</configuration>

Also check that the the MapTest framework dll's are not blocked by windows, I had to unblock them by selecting the file, opening the properties and the click the "Unblock" button. If the button is not visible the files are already unblocked. (I had to do this for the following filesMapTestFramework.Common.dll, nunit.framework.dll, XmkUnit.dll)