In this article, I’ll explain how we resolve 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 are writing one PowerShell script and testing in between to verify the result. Following is the sample code snippet, which 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 =" " #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
-
- $clientContext.Load($web)
- $clientContext.ExecuteQuery()
Issue
The issue is in the PowerShell script, mentioned above; we are getting the exception, mentioned below, 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
+ $clientContext.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : MissingMethodException
This exception took us lot of time to solve so I thought to share :)
Solution
We are really wondering why suddenly such an error is coming up 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 but no luck.
The only thing which we realized is that my laptop was formatted and the support team installed .NET Framework, client component SDK and the modules, mentioned below that are required for Office 365, SharePoint Online.
- Microsoft Online Service Sign-in Assistant for IT Professionals RTW.
- Windows Azure Active Directory Module for Windows PowerShell (64-bit version).
- SharePoint Online Management Shell.
After looking at the installed software, I realized that there is .NET Framework 4, which 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 the script is executed successfully without any issue.
Here, I’ll share a complete list of the 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
- Windows Management Framework 3.0 or Windows Management Framework 4.0
References