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" ?>
<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"/>
2. Add an entry like
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.