SharePoint Online/Office 365 - Resolved Exception "Method Not Found: 'Boolean System.Net.WebResponse.get_SupportsHeaders()'."

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.

  1. # add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM  
  2.   
  3. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
  4.   
  5. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  
  6.  
  7. #Specify tenant admin and URL  
  8. $User = "" # Your tenant user id goes here  
  9.  
  10. #Configure Site URL and User  
  11. $SiteURL = "" #Your tenant site URL  
  12.  
  13. #Password  
  14. $Password =" " #Password  
  15.  
  16. #Convert password to secure string  
  17. $securePassword = ConvertTo-SecureString -String $Password -AsPlainText –Force  
  18.   
  19. $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$securePassword)  
  20.  
  21. #Instantiating the client context object and setting the credentials   
  22. $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)  
  23. $Context.Credentials = $Creds  
  24.  
  25. #Getting web instance and loading it  
  26. $web = $clientContext.Web  
  27.   
  28. $clientContext.Load($web)  
  29. $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.
  1. Microsoft Online Service Sign-in Assistant for IT Professionals RTW.
  2. Windows Azure Active Directory Module for Windows PowerShell (64-bit version).
  3. 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.

  1. 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

  2. .NET Framework 4.5.x - Installing the .NET Framework
  3. Windows Management Framework 3.0 or Windows Management Framework 4.0

References