I came across the error The type initializer for 'System.Management.Automation.Runspaces.InitialSessionState' threw an exception. when trying to compile the c# in ASP.NET code using Visual Studio.
Solved
Open Control Panel > Install / Uninstall Programs > .NET 3.5 SP1 > Repair