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