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 :  3    Total :   14907
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial

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" ?> 
 <startup useLegacyV2RuntimeActivationPolicy="true"> 
 <supportedRuntime version="v4.0" />

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

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

2. Add an entry like

   <NetFx40_LegacySecurityPolicy enabled="true"/>

3. Add an entry like

   <legacyCasPolicy enabled="true" />

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.

Migratiin Tools for SharePoint