cdanielm58 / google-api-dotnet-client

Automatically exported from code.google.com/p/google-api-dotnet-client
Apache License 2.0
0 stars 0 forks source link

Google.Apis.Authentication.OAuth2 binding issue #353

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following C# code:

        private static IAuthenticator CreateAuthenticator(Func<NativeApplicationClient, IAuthorizationState> authProvider)
        {
            D.Func();
            NativeApplicationClient client = new NativeApplicationClient(GoogleAuthenticationServer.Description);
            client.ClientIdentifier = CLIENT_ID;
            client.ClientSecret = CLIENT_SECRET;
            return new OAuth2Authenticator<NativeApplicationClient>(client, authProvider);
        }

rises an exception for some Windows 7 users:

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.

I cannot reproduce the problem on my machines. I suspect that the problem might 
be in binding. Google.Apis.Authentication.OAuth2.dll was compiled against 
Google.Apis.dll Version=1.4.0.28223, while the latest 
google-drive-v2-rev83-csharp-1.4.0-beta package contains Google.Apis.dll 
Version=1.4.0.28227.

See here for possible issue reason here: 
http://stackoverflow.com/questions/948785/typeloadexception-says-no-implementati
on-but-it-is-implemented

Original issue reported on code.google.com by ext.andr...@gmail.com on 11 Jul 2013 at 9:19

GoogleCodeExporter commented 9 years ago
More and more users report this issue. Though it is only a small fraction of 
the total user base.

Original comment by ext.andr...@gmail.com on 12 Jul 2013 at 1:19

GoogleCodeExporter commented 9 years ago
There are compilation warnings (even in the Drive sample project):

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

They occur only if a project references System.Net (as recommended in the Build 
guide). I suspect that this is related somehow with the 
System.TypeLoadException error, because ApplyAuthenticationToRequest() method 
has exactly HttpWebRequest param. So, it seems something wrong with Google 
Apis/OAuth/Drive binding. And it seems was caused by making Google.Apis a 
Portable Class Library.

Original comment by ext.andr...@gmail.com on 13 Jul 2013 at 5:04

GoogleCodeExporter commented 9 years ago
1. What is the difference in the machine, VS version, .NET framework installed 
between the users who run without errors \ warnings to users who run 
successfully?
2. Is .NET 4.0 installed on all the machines?

Original comment by pele...@google.com on 13 Jul 2013 at 6:40

GoogleCodeExporter commented 9 years ago
.NET 4 (Full profile) is installed on all machines (it is required by the 
installer). I have no idea about the differences. I cannot reproduce the error 
on my own PCs, which all have VS 2010 installed. The users probably don't have 
VS on their machines.

I asked several users to install Fusion Log Viewer and send its logs. I will 
post the logs here as soon as (or if) I have them.

PS. For now I am rolling back to Google.Apis version 1.3.

Original comment by ext.andr...@gmail.com on 13 Jul 2013 at 6:46

GoogleCodeExporter commented 9 years ago
Can you check if System.Net.dll appears in the GAC? 
Did you try adding a reference to that system dll?

Original comment by pele...@google.com on 13 Jul 2013 at 9:02

GoogleCodeExporter commented 9 years ago
I did add a reference to System.Net.dll in my own library (GDrive.dll), which 
is used by the main app. Here you can find the app binaries and examine their 
references: http://safeincloud.s3.amazonaws.com/v1.6/SafeInCloud_Debug.zip

System.Net.dll v4.0.30319.233 exists in the GAC on my machines (where I cannot 
reproduce the bug). I will ask users to check this on machines, where the bug 
is reproduced. Though I believe this dll is a part of .NET 4 (which is required 
by the app installer) and cannot be missing.

Original comment by ext.andr...@gmail.com on 14 Jul 2013 at 5:14

GoogleCodeExporter commented 9 years ago
How did you add the system dll? 
Did you add a reference and browse to its location (c:\Program Files 
(x86)\Reference 
Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Net.dll) or add a 
framework assembly (from the aff reference assembly under assemblies --> 
Framework, as you can see from the attached picture)?

It sound to me that you add a reference to System.Net.dll in the right way, but 
it worth checking that before we continue to investigate...

Original comment by pele...@google.com on 14 Jul 2013 at 3:13

Attachments:

GoogleCodeExporter commented 9 years ago
I've added System.Net reference via the ".NET" tab (in VS 2010), not via 
browsing.

Original comment by ext.andr...@gmail.com on 14 Jul 2013 at 3:50

GoogleCodeExporter commented 9 years ago
And where is exactly this System.Net,dll in the users machine? Is it in a 
different location?
Can you try add Microsoft.Net.Http package using NuGet in both your project and 
the main app as well (and please do the same for Microsoft.Bcl.Async)

I'll try to "play" with it in the next days, creating a class library using the 
Drive API, and then a console application which uses that library.

Original comment by pele...@google.com on 15 Jul 2013 at 12:10

GoogleCodeExporter commented 9 years ago
Until now I haven't got any replies from the users, whom I asked to collect 
Fusion logs. So, I have no idea about their system configurations and dll 
locations. I will attach the logs here as soon as I have them.

I downgraded my app to Google.Apis to 1.3.0-beta and cannot assist you with 
this anymore. I believe that you should find the reason of the CS1684 
compilation warnings. This might explain the runtime error.

Original comment by ext.andr...@gmail.com on 15 Jul 2013 at 4:42

GoogleCodeExporter commented 9 years ago
Here are the Fusion logs from on of the users, who can reproduce the problem. 
Hope it helps.

Original comment by ext.andr...@gmail.com on 15 Jul 2013 at 8:04

Attachments:

GoogleCodeExporter commented 9 years ago
It looks like you don't have references to System.Net.Http and 
System.Net.Http.Primitives (and maybe other dlls as well, I didn't see them in 
your fusion log file)

I attached my fusion log.

1. Can you send me your project file?
2. Can you send me the content of your build (bin\Release or bin\Debug) folder? 
System.Net.Http.dll should appear there...

I think you are missing some important references, but we will continue to 
investigate that together and I'm pretty sure we will find it very very soon.

Thanks for the collaboriation,
Eyal

Original comment by pele...@google.com on 15 Jul 2013 at 1:31

Attachments:

GoogleCodeExporter commented 9 years ago
Here are the binaries: 
http://safeincloud.s3.amazonaws.com/v1.6/SafeInCloud_Debug.zip
The mentioned dlls are in place.

The project files are attached.

Original comment by ext.andr...@gmail.com on 15 Jul 2013 at 1:46

Attachments:

GoogleCodeExporter commented 9 years ago
An here are the Fusion logs from my machine, where I cannot reproduce the bug.

Original comment by ext.andr...@gmail.com on 15 Jul 2013 at 1:49

Attachments:

GoogleCodeExporter commented 9 years ago
I spend the last two hours trying to figure out why you having this problem, 
but I still didn't come with a conclusion.

Here what I discovered:

1. I managed to run your SafeInCloud.exe in my Windwos 7 machine - it just 
worked.
The weird thing is that even after I deleted all your bin files, and left only 
the exe file, the application still worked. It looks like you are wrapping all 
the dependencies into your exe or something similar to that... Makes sense? Try 
it yourself.

2. The main difference between the user's fusion log to your fusion log is that 
in the user's fusion log following dlls are missing:
log4net,
Microsoft.Threading.Tasks,
System.Net.Http.Primitives,
System.Net.Http, Version=1.5.0.0,
System.Net.Http, Version=2.1.10.0, (I don't know why there two different 
version, we may try to understand it later on)
System.Numerics,
Zlib.Portable,

3. I created a drive library (which uses the Drive API) using the instructions 
in our build page. Then I created a console application which uses this new 
drive library. It works for me. 
I also saw that my bin folder contains a lot of files which are missing in your 
debug folder, like the following files:

Microsoft.Threading.Tasks.Extensions.Desktop.dll
Microsoft.Threading.Tasks.Extensions.dll
System.Net.Http.Extensions.dll
System.Net.Http.WebRequest.dll

4. I also didn't manage to compile my library (similar to your GDrive) without 
adding app.config with the content which is recommended in our build page.

So my recommendations are (please try them separately)

5. Try to add the app.config with the right content to your GDrive project.

6. Can you just copy the files I mentioned in bullet 3 to your Debug folder and 
then try to run it from your users machine?

7. Can you please run the Drive sample API 
(http://samples.google-api-dotnet-client.googlecode.com/hg/Drive.Sample/README.h
tml) and let me know if it works for you?

8. Is it possible that if those steps won't work for you, you will try to 
install VS2012 Express, and we will try to check if the same problem occurs 
there too. Don't do that yet, I'm just asking...

Original comment by pele...@google.com on 15 Jul 2013 at 4:44

GoogleCodeExporter commented 9 years ago
1. Safe In Cloud runs in the background. You probably just didn't close it 
properly. That's why deleting dlls didn't work. Select 'Exit' from its tray 
icon menu or 'File' > 'Exit Safe In Cloud' in the main menu.

2-9. Sorry, I cannot assist you with this, because I cannot reproduce the 
problem on my machines. And asking the users to do all such stuff is very 
painful and slow (e.g. only one user of ten sent me the Fusion logs with a two 
days delay).

I suggest you to contact the developer, who reported the same bug here:
https://code.google.com/p/google-api-dotnet-client/issues/detail?id=350

He can reproduce the problem on his own machine and hence you can solve the 
problem much faster.

PS. Maybe you have some testing machines in Google and can try to find a 
configuration, where the bug is reproduced?

PPS. And try to figure out the reason of the CS1684 compile warnings.

PPPS. Google.Apis v1.3.0-beta works fine for the users, on whose machines 
v1.4.0-beta fails.

Original comment by ext.andr...@gmail.com on 15 Jul 2013 at 5:05

GoogleCodeExporter commented 9 years ago
I'll continue to investigate issue 350. Let me know when you have time to check 
those suggestions I sent you.
I'm pretty sure that in the long run you want to upgrade and use the latest 
changes. e.g. resumable upload was improved in 1.4.0-beta and media downloader 
was implemented. Let me know,
Eyal

And another question, do the completion errors in the Drive sample occurred in 
your machine as well? Did you manage to run it successfully?

Original comment by pele...@google.com on 15 Jul 2013 at 8:46

GoogleCodeExporter commented 9 years ago
Which .NET version did you installed in you client?
I'm using 4.0.30319

Original comment by pele...@google.com on 17 Jul 2013 at 1:23

GoogleCodeExporter commented 9 years ago
I suspect that it happens only to users which our client was already installed 
there. Am I correct? If you can follow my latest comment on issue 350 and try 
my suggestion there it will be great. Thanks!

Original comment by pele...@google.com on 17 Jul 2013 at 4:20

GoogleCodeExporter commented 9 years ago
As I wrote you before, I have no access to machines, where the bug can be 
reproduced. So, I cannot perform any tests.

As for your guess, cannot you check it using the Fusion logs I've attached 
above?https://code.google.com/p/google-api-dotnet-client/issues/detail?id=353#c1
1

Original comment by ext.andr...@gmail.com on 17 Jul 2013 at 9:34

GoogleCodeExporter commented 9 years ago
You said that the problem occurred to some users (not all of them, actually you 
said a small fraction of them), so my question is the following:
Can you please figure out if you can find something those users shares (e.g. 
all of the users which are complaining about the new version, had already 
installed an older version with the old Google.Apis.Authentication.OAuth2.dll. 
In that case they may have in their GAC an older version of the library).

Thanks,
Eyal 

Original comment by pele...@google.com on 18 Jul 2013 at 12:00

GoogleCodeExporter commented 9 years ago
I have the same problem, I haven't installed any versions using NuGet or 
otherwise before, just downloaded the 1.4 DLLs. 
It works fine on my laptop in Win7, but on my server in Win2008 R2 gives the 
same exception. 
I checked and all .Net installations was exactly the same versions, both x64 
machines.

Original comment by ysalimp...@gmail.com on 23 Jul 2013 at 3:52

GoogleCodeExporter commented 9 years ago
hi ysalimpour,
because I didn't receive this error, is there any way that you can share your 
screen using hangout or similar application, it could be very helpful to 
finally solve this issue!

It is very hard to try solving this without seeing it happen.

Thanks for the collaboration,
Eyal

Original comment by pele...@google.com on 23 Jul 2013 at 4:02

GoogleCodeExporter commented 9 years ago
Well unfortunately it doesn't happen on my development box and I can't share 
the production machine screen, but here are both Fusion logs from the machine 
which works fine and the one that doesn't.
https://www.dropbox.com/s/5uvfz4rkmr46u5c/FusionLogs-Working.zip
https://www.dropbox.com/s/4md4jt0hv85q5nl/FusionLogs-NotWorking.zip

Also here is the full exception:
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.
   at MobileUtils.Scripts.ImportFromAnalytics.Run()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Is there any other info that I can provide?

Original comment by ysalimp...@gmail.com on 23 Jul 2013 at 8:03

GoogleCodeExporter commented 9 years ago
Can you try to do the following:
In your project's References folder there should be a reference to this dll, 
and the version should be 2.0.0.0. Make sure this is set to Copy Local = true. 
And then make sure it finds its way to your server app's bin folder.

This is one of the libraries that is now managed by nuget. So open Nuget and 
make sure everything is up to date. And in your projects packages directory the 
file should be here: \packages\System.Net.Http.2.0.20126.16343\lib\net40

You could also try creating a new MVC4 app and see if the file shows up for 
that one.

From 
http://stackoverflow.com/questions/9431975/could-not-load-file-or-assembly-syste
m-net-http-version-2-0-0-0-in-mvc4-web-ap

Please also try what is offered here - 
http://stackoverflow.com/questions/17815102/unable-to-build-project-with-google-
apis-net

I would be happy to test it myself, but I can't reproduce it.

Please update me ASAP, and let me know what works for you, so other users will 
be able to solve that as well.

Thanks a lot!
Eyal

Original comment by pele...@google.com on 23 Jul 2013 at 8:52

GoogleCodeExporter commented 9 years ago
Thanks,
There is a reference to System.Net.Http but it's not 2.0.0.0 its the one that 
is shipped with google-api-dotnet-client-1.4.0-beta.binary which is 2.1.10.0.
I'll try NuGet and tell you the results.

Original comment by ysalimp...@gmail.com on 23 Jul 2013 at 9:11

GoogleCodeExporter commented 9 years ago
I think you should try to use the 2.1.10.0 as well but make sure that Copy 
Local = true.

Let me know

Original comment by pele...@google.com on 23 Jul 2013 at 9:14

GoogleCodeExporter commented 9 years ago
I installed the package using NuGet but it didn't help either.
As far as i can tell the difference it made was a couple of more dll 
redirections in app config file and a slightly newer versions of Google DLLs.
I'm sure that all the mentioned DLLs are CopyLocal=true and they are being 
copied to the release folder.

Can't you suggest any way to receive a more detailed error message to find out 
the actual problem? or you're positive that it's System.Net.Http?

I keep looking into it and will send if I found anything else.

Original comment by ysalimp...@gmail.com on 24 Jul 2013 at 4:38

GoogleCodeExporter commented 9 years ago
I'm pretty sure it System.Net and System.Net.Http that cause the problem, just 
because the method that throws the exception (ApplyAuthenticationToRequest) 
gets a WebHttpRequest as parameter (which is defined in System.Net)

Can you try to change the reference to System.Net and the other System.Net.xxx 
to "Copy Local = true" 
It also worth to check this StackOverflow topic - 
http://stackoverflow.com/questions/17815102/unable-to-build-project-with-google-
apis-net

Original comment by pele...@google.com on 24 Jul 2013 at 1:09

GoogleCodeExporter commented 9 years ago
Well I finally got it fixed by installing .Net framework 4.5! 
I'm sorry I wasn't able to find the exact problem, but when i was going to run 
GoogleApi own samples I decided to try them with binaries build upon .Net4.5 
then I found out there isn't .net4.5 on my server, So I installed it and my 
program started to work.
I know I told you before that .net installations was exactly the same, I 
concluded that from folders in Windows/Microsoft.Net which now I've found out 
that existence of a folder doesn't mean that .net version has been installed.

Anyway thanks for your suggestion and i hope my solution helps others too.

Original comment by ysalimp...@gmail.com on 24 Jul 2013 at 6:41

GoogleCodeExporter commented 9 years ago
Can you try the following (from 
http://stackoverflow.com/questions/18060340/asp-net-using-analytics-reporting-ap
i-does-not-work-on-server) and let me know:

"Copying System.Net.Http from the bin and replacing the one in 
C:\Windows\Microsoft.NET\Framework64\v4.0.30319 worked!" by user1697748

Original comment by pele...@google.com on 13 Aug 2013 at 11:58

GoogleCodeExporter commented 9 years ago
For what it's worth...

I had the same problem, realized I had not updated my Windows 7 Virtual Machine 
in a while, updated with Windows 7 Service Pack 1 and now my Drive API sample 
works correctly.

Original comment by jamey.bl...@gmail.com on 31 Aug 2013 at 10:53

GoogleCodeExporter commented 9 years ago
It helps a lot. Thanks for sharing that with us.

Original comment by Pele...@gmail.com on 1 Sep 2013 at 3:22

GoogleCodeExporter commented 9 years ago
Hi all (as requested on StackOverflow), I'm having the same issue.  Not sure 
what details you want, but let me know and i will happily give you as much info 
as you need.

My email is chris.jones@dc-storm.com

Original comment by chrisajo...@gmail.com on 2 Sep 2013 at 8:07

GoogleCodeExporter commented 9 years ago
Hi,
two things:

1. If you run on Windows 7, please try to update to Service Pack 1.
2. Do you work with the latest NuGe version?
3. If you still encounter problems, I would like to have a Hangout with you and 
if it's OK it will be great if you would share your screen.
Let me know, and I'll contact you base on your response.

Thanks for the collaboration,
Eyal

Original comment by pele...@google.com on 3 Sep 2013 at 12:57

GoogleCodeExporter commented 9 years ago
Thanks for getting back to us Eyal.  

I am running Win7 sp 1.

Nuget version = 2.7.40808.167.

Im happy to have a Hangout, let me know how and when.

Chris

Original comment by chrisajo...@gmail.com on 3 Sep 2013 at 1:39

GoogleCodeExporter commented 9 years ago
So you need to install Hangout
http://www.google.com/+/learnmore/hangouts/
It's very easy.

Can we schedule to later on today? I'm available from 3pm EST

Original comment by pele...@google.com on 3 Sep 2013 at 1:55

GoogleCodeExporter commented 9 years ago
I have installed Hangouts, but i wont be available at 3pm EST.  Im in London on 
British Summer Time (BST).  

Earlier today, or tomorrow would be good.

Chris

Original comment by Peter.To...@dc-storm.com on 3 Sep 2013 at 2:13

GoogleCodeExporter commented 9 years ago
Did you get my invitation for tomorrow at 10 EST?

Original comment by pele...@google.com on 3 Sep 2013 at 5:50

GoogleCodeExporter commented 9 years ago
No, i think my computer was signed into a different account, can you try this 
one:

chris.jones@dc-storm.com

Original comment by Chris.Jo...@dc-storm.com on 3 Sep 2013 at 7:45

GoogleCodeExporter commented 9 years ago

Original comment by pele...@google.com on 17 Sep 2013 at 3:23

GoogleCodeExporter commented 9 years ago
Solution is given in 
https://code.google.com/p/google-api-dotnet-client/issues/detail?id=350

Original comment by ranjan2...@gmail.com on 18 Sep 2013 at 6:25

GoogleCodeExporter commented 9 years ago
Hi, 
I'm also getting the above error, It doesn't occur on my local machine or 
another enviroment like the dev but occurs on QA environment. while both thw 
servers have same configuration and asp.net version 4.0.3019

I'm unable to figure out the possible solution. any help would be appreciable.

Original comment by mahesh...@gmail.com on 26 Sep 2013 at 4:34

GoogleCodeExporter commented 9 years ago
This thread is full with different errors.
Can you start a new thread, add a reference to this one, and have as much 
information as you can. 
Visual Studio version, Windows version, .NET framework, ...

Original comment by pele...@google.com on 27 Sep 2013 at 2:37

GoogleCodeExporter commented 9 years ago
Hi
I am trying to google translate sample but the below error is being appeared in 
the browser
Could not load file or assembly 'Google.Apis.Authentication.OAuth2' or one of 
its dependencies. This assembly is built by a runtime newer than the currently 
loaded runtime and cannot be loaded. 
I have installed VS Framework 4.0 but still same error is being continued.
Can someone help me out?

Original comment by swaroopi...@gmail.com on 1 Oct 2013 at 7:25

GoogleCodeExporter commented 9 years ago
If you want to use the translate API you don't need to work with the 
Authentication package.
Take a look in our translate sample - 
https://code.google.com/p/google-api-dotnet-client/source/browse?repo=samples#hg
%2FTranslate.TranslateText. 

Original comment by pele...@google.com on 1 Oct 2013 at 2:03

GoogleCodeExporter commented 9 years ago
The full solution is as following:
1. Make sure your .NET framework is patched. Microsoft released patches to .NET 
to allow Portable Class Libraries to properly find the appropriate runtime 
(KB2468871). If you are seeing the above exception (or something like it), it 
means you're missing the latest .NET framework patches.

2. Install .NET 4.0 full profile 

Original comment by pele...@google.com on 3 Oct 2013 at 12:54