0

When I run my asp.net application on local host everything works great but when i publish my app on the web server this error shows up:

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.

Here is part of the code that uses analytic

.............................................

                //This is the API url which we're storing to a string
                string scope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue();

                //For whatever reason, this is labelled wrong. It is the email address
                //that you have added as a user to your Analytics account
                string clientId = "*********@developer.gserviceaccount.com";

                //This is the physical path to the file we downloaded earlier
                //To demonstrate this, I've kept the full path to my key file.
                //Obviously, you will need to change this to match where you've
                //stored yours.
                string keyFile = @"C:\key\*************76-privatekey.p12";

                //The password Google gives you, probably the same as the one below
                string keyPassword = "notasecret";

                //Store the authentication description
                AuthorizationServerDescription desc = GoogleAuthenticationServer.Description;

                //Create a certificate object to use when authenticating
                X509Certificate2 key = new X509Certificate2(keyFile, keyPassword, X509KeyStorageFlags.Exportable);

                //Now, we will log in and authenticate, passing in the description
                //and key from above, then setting the accountId and scope
                AssertionFlowClient client = new AssertionFlowClient(desc, key)
                {
                    ServiceAccountId = clientId,
                    Scope = scope
                };

                //Finally, complete the authentication process
                //NOTE: This is the first change from the update above
                OAuth2Authenticator<AssertionFlowClient> auth =
                    new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);

                //First, create a new service object
                //NOTE: this is the second change from the update
                //above. Thanks to James for pointing this out
                AnalyticsService gas = new AnalyticsService(new BaseClientService.Initializer() { Authenticator = auth });

                //Create our query
                //The Data.Ga.Get needs the parameters:
                //Analytics account id, starting with ga:
                //Start date in format YYYY-MM-DD
                //End date in format YYYY-MM-DD
                //A string specifying the metrics

                DataResource.GaResource.GetRequest r =
                    gas.Data.Ga.Get(googleID[0]["google_analytic_id"].ToString(), "2005-01-01", DateTime.Now.ToString("yyyy-MM-dd"), "ga:visitors");

                //Specify some addition query parameters
                //    r.Dimensions = "ga:pagePath";
                r.Sort = "-ga:visitors";
                r.MaxResults = 5;

                //Execute and fetch the results of our query
                GaData d = r.Execute();
user1697748
  • 323
  • 1
  • 3
  • 11
  • Which web server do you use? See the following thread http://stackoverflow.com/questions/17815102/unable-to-build-project-with-google-apis-net regrading a similar problem to this one. – peleyal Aug 05 '13 at 17:39
  • Webserver is IIS 7. What throws me off here is that it builds and runs fine in local host so you would think it has all the proper references and dependencies..But after publishing it we get this "ApplyAuthenticationToRequest does not have an implementation..." – user1697748 Aug 05 '13 at 20:00
  • Take a look in http://stackoverflow.com/questions/9431975/could-not-load-file-or-assembly-system-net-http-version-2-0-0-0-in-mvc4-web-ap,maybe you can find important information there. What .NET version are you using? 4.0 or 4.5? – peleyal Aug 06 '13 at 12:38
  • It's a webform using 4.0. I tried on another server just to see (IIS 6) and still get the same error. I will keep looking and trying out stuff with the links you provided... – user1697748 Aug 06 '13 at 14:01
  • It is due to security issue. In my case on the request get authenticated when my application uses visual web development server port.But it were failing otherwise.Then i tried to host my application outside the current network security and it works like charm. Which version of Api you are using? V2 or V3. Please let us see your code – Kamran Shahid Aug 07 '13 at 11:50
  • I updated the post with the code. The version used is V3 – user1697748 Aug 08 '13 at 13:21
  • Hi user1697748, does the problem still occur? If so , try to attach fusionlog output. I saw that problem before, I'm not sure in 100%, but it looks like you use System.Net.Http and similar assemblies from your GAC or from a folder in the PATH maybe, but they aren't exist in your web server. Let me know... I'm curious. – peleyal Aug 11 '13 at 20:16

1 Answers1

0

I have the same problem. Have no solution yet, but:

I testing google apis in an MVC project using .net framework 4.0, where I have added google apis with nugets. The project works fine in VS Express 2012 for web, but I got the same crash when I publish the project to an IIS7 server running .NET Framework Version:4.0.30319. I have verified that the two machines are using the same assemblies.

Something differs and I dont know what!

tornord
  • 336
  • 4
  • 8
  • Is it the exact same crash? I also added everything with nugets – user1697748 Aug 12 '13 at 16:09
  • Can you guys try follow the instructions in http://stackoverflow.com/questions/16756186/system-net-http-could-not-be-resolved-in-the-currently-targeted-framework-net-4 I think that the problem is based on the HttpClient package we are using. I wan't able to reproduce it in my machine. I'll create a new fresh virtual machine soon, so I'll be able to check that. Meantime please let me know – peleyal Aug 12 '13 at 19:52
  • Hello peleyal Copying System.Net.Http from the bin and replacing the one in C:\Windows\Microsoft.NET\Framework64\v4.0.30319 worked! – user1697748 Aug 12 '13 at 21:32