Thursday, 10 November 2016

SharePoint Online / Office 365 - Resolved exception "Method not found: 'Boolean System.Net.WebResponse.get_SupportsHeaders()'."

Hi All,

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
+ $clientContext.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + 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
  1. Windows (64 bit)
    1. Windows 7 with service pack1
    2. Windows 8 or Windows 8.1
    3. Windows server 2008 R2 SP1
    4. Windows server 2012 or Windows server 2012 R2
  2. .Net Framework 4.5.x - Installing the .NET Framework
References: Connect to all Office 365 services in a single Windows PowerShell window - 
Manage Office 365 with Office 365 PowerShell - 
Getting started with Office 365 PowerShell - 
Office 365 PowerShell for SharePoint Online - 
Enjoy Reading :)
As usual any comment / suggestions / feedback / questions always welcome :)


keerthi said...

I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work..

Sharepoint Training in Chennai

Prasham Sabadra said...

Thanks Keerthi!