In this article, I’ll explain how we resolved exception "Method not found: 'Boolean System.Net.WebResponse.get_SupportsHeaders()'." while calling “ExecuteQuery” method of ClientContext in PowerShell script while executing against SharePoint online / Office 365. Finally I’ll also share the software requirements to access/manage/connect Office 365/SharePoint online and few references.
Background: We have writing one PowerShell script and testing in between to verify the result.
Following is the sample code snippet we executed and ran the script.
# add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Specify tenant admin and URL
$User = "" # Your tenant user id goes here
#Configure Site URL and User
$SiteURL = "" #Your tenant site URL
$Password =" " #Password
#Convert password to secure string
$securePassword = ConvertTo-SecureString -String $Password -AsPlainText –Force
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$securePassword)
#Instantiating the client context object and setting the credentials
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Context.Credentials = $Creds
#Getting web instance and loading it
$web = $clientContext.Web
Issue: Issue is in above PowerShell script we are getting following exception on $clientContext.ExecuteQuery()
Exception calling "ExecuteQuery" with "0" argument(s): "Method not found: 'Boolean System.Net.WebResponse.get_SupportsHeaders()'."
At C:\PowerShell\Mostlyused.ps1:73 char:1
+ CategoryInfo : NotSpecified: (:) , MethodInvocationException
+ FullyQualifiedErrorId : MissingMethodException
This exception took us lot of time to solve so thought to share :)
Solution: We are really wondering why suddenly such error is coming since PowerShell scripts were running fine before. We already executed lots of scripts without any issues.
We verified UserName, PassWord, SiteURL and everything seems to be fine. We googled a lot bit but no luck.
Only thing we realized that my laptop was formatted and support team installed the .Net Framework, client component SDK and following modules that are required for Office 365, SharePoint Online
After again looking at software installed I realized that there is .Net Framework 4 is installed but to access/manage/connect to Office 365/SharePoint online we need .Net Framework 4.5.x. We have installed .Net Framework 4.5 and script executed successfully without any issue.
Here, I’ll share complete list of required SWs required for accessing/managing/connecting to Office 365/SharePoint online using PowerShell
- Windows (64 bit)
- Windows 7 with service pack1
- Windows 8 or Windows 8.1
- Windows server 2008 R2 SP1
- Windows server 2012 or Windows server 2012 R2
- .Net Framework 4.5.x - Installing the .NET Framework
References: Connect to all Office 365 services in a single Windows PowerShell window - https://technet.microsoft.com/en-us/library/dn568015.aspx
Manage Office 365 with Office 365 PowerShell - https://technet.microsoft.com/en-us/library/dn568031.aspx
Getting started with Office 365 PowerShell - https://technet.microsoft.com/en-us/library/dn568011.aspx
Office 365 PowerShell for SharePoint Online - https://technet.microsoft.com/library/fp161362.aspx
Enjoy Reading :)
As usual any comment / suggestions / feedback / questions always welcome :)