Showing posts with label HttpWebRequest. Show all posts
Showing posts with label HttpWebRequest. Show all posts

Tuesday, October 15, 2013

ApplyAuthenticationToRequest errors

In the last months, just a few weeks after releasing 1.4.0-beta version of the Google APIs client library for .NET, I was asked by several developers about the following error:
System.TypeLoadException: Method 'ApplyAuthenticationToRequest' in type 'Google.Apis.Authentication.OAuth2.OAuth2Authenticator`1' from assembly 'Google.Apis.Authentication.OAuth2, Version=1.4.0.28223, Culture=neutral, PublicKeyToken=null' does not have an implementation.

This error also occurred after releasing 1.5.0-beta (Version=1.5.0.28991). The most problematic issue was that I didn't succeed in reproducing it on my machine and I spent a lot of time trying to figure out what is the exact problem ("But It works ON MY MACHINE!").

I understood then that the real problem wasn't our implementation of ApplyAuthenticationToRequest, but was based on the usage of System.Net assembly, in particular on the parameter to ApplyAuthenticationToRequest - System.Net.HttpWebRequest.
In addition, other developers also complained about the following compilation warnings:
warning CS1684: Reference to type 'System.Net.HttpWebRequest' claims it is defined in 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Net.dll', but it could not be found
warning CS1684: Reference to type 'System.Net.WebResponse' claims it is defined in 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Net.dll', but it could not be found
warning CS1684: Reference to type 'System.Net.WebRequest' claims it is defined in 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Net.dll', but it could not be found

So... I investigated and investigated and had several different directions - does it depend on the Windows platform (Vista, Windows 7 and Windows 8), what is the different in the GAC content, etc.

To make a long story short, just lately we found out the core of all evil.
Users who encounter this error should install KB2468871 patch for the .NET framework 4. This patch includes a new version of System.Net.dll (and other core assemblies as well) and it solves this issue.

Special thanks to the owners of Microsoft.Net.Http package which helped a lot in investigating this issue and refer me to this article, and specifically to the following section:
If you target the .NET Framework 4 or later, the computer must have the .NET Framework 4 with an update, Update 4.0.3 for the .NET Framework 4, or the .NET Framework 4.5 installed.

Thanks also to our developers for reporting the issue, for collecting all the data I asked them to, and for offering solutions.


Nahal Mishmar, April 2013, Israel

Eyal