System.NotSupportedException: This method explicitly uses CAS policy, which has been obsoleted by the .Net Framework – PowerShell in SharePoint 2013

Sathish Nadarajan
 
Solution Architect
December 11, 2013
 
Rate this article
 
Views
18638

When I was working with PowerShell, some of the methods, when I try to access, I got the above mentioned exception. After investigating sometime, identified that the problem is with the Config file of the PowerShell.exe.

The Config file is located on C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe.config

The file looks like

 <?xml version="1.0" encoding="utf-8" ?> 
 
 <configuration> 
 
 <startup useLegacyV2RuntimeActivationPolicy="true"> 
 
 <supportedRuntime version="v4.0" />
 
 </startup> 
 
 </configuration>
 
 

Now, what we need to do is, we need to remove those Startup Tag. That’s it. Solved our problem. Hope this small tip can save few hours of someone who really faces this kind of issue.

The related stuff which I identified while investigating for myself are as follows. Probably am consolidated all the points which I gathered while surfing various sites and MSDN articles. If the above didn’t solve your issue, then you could try with the below options.

From my understanding, I came to know that, this is purely because the IDEs which we are using. Even the same kind of exception can happen on the Visual Studio also. At that time, we need to modify the config of the Devenv.exe.config.

1. Add an entry like

 <system.web>
         <trust level="Full" legacyCasModel="true"/>
 </ system.web> 
 
 
 

2. Add an entry like

 <runtime>
   <NetFx40_LegacySecurityPolicy enabled="true"/>
 </runtime>
 

3. Add an entry like

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

The values which mentioned above should be made on the config files of the corresponding EXEs. If this is happening on the WebApplication, try adding it on the Web.Config file.

Happy Coding.

Sathish Nadarajan.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment