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


Sathish Nadarajan
SharePoint MVP
Published On :   11 Dec 2013
Visit Count
Today :  1    Total :   15086
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

Sharegate: Kick-Ass Tool
Think Your SharePoint & Office 365 Are Secure ? Find Out Now!


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.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

KWizCom Scan