googleads / google-ads-dotnet

This project hosts the .NET client library for the Google Ads API.

Home Page:https://developers.google.com/google-ads/api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Method not found

scamner opened this issue · comments

I keep trying to use the version 11 library to connect to Google Ads API, but I keep getting this error. I am running it from my laptop at home, so wide open internet. I got my permanent Google OAuth 2 client ID and secret that I added to my app.config, but I keep getting the below.

Grpc.Core.RpcException: 'Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1655732174.917000000","description":"Failed to pick subchannel","file":"......\src\core\ext\filters\client_channel\client_channel.cc","file_line":3218,"referenced_errors":[{"created":"@1655732174.917000000","description":"failed to connect to all addresses","file":"......\src\core\lib\transport\error_utils.cc","file_line":165,"grpc_status":14}]}")'

So, I upgraded to version 12.1.0 of Google.Ads.GoogleAds and the above error went away, but now I get....

Method not found: 'Void Google.Api.Gax.Grpc.ClientHelper..ctor(Google.Api.Gax.Grpc.ServiceSettingsBase)'.

Could you try adding a dependency to Google.Ads.Gax package? It should have been pulled directly because it is a dependency to Google.Ads.GoogleAds, but perhaps there's something weird going on...

A minimal demo project to illustrate this issue would also be very helpful.

Google.Ads.Gax is added to the project.

Here is the main page that I am running. I tried to zip and send the project, but it's too big even minimally and I do not have it in github.

using Google.Ads.GoogleAds;
using Google.Ads.GoogleAds.Lib;
using Google.Ads.GoogleAds.Util;
using Google.Ads.GoogleAds.V11.Errors;
using Google.Ads.GoogleAds.V11.Services;
using System;

namespace SendCallData
{
class Program
{
static void Main(string[] args)
{
GoogleAdsClient client = new GoogleAdsClient();
TraceUtilities.Configure(TraceUtilities.DETAILED_REQUEST_LOGS_SOURCE,
"C:\test\logs\details.log", System.Diagnostics.SourceLevels.All);

        Run(client, 7043240301, "+18553150446", "2022-01-27 03:48:53 +0:00", "2022-01-19 10:36:37 -4:00", 15, null, null);
    }

    static void Run(GoogleAdsClient client, long customerId, string callerId, string callStartTime, string conversionTime, double conversionValue,
        long? conversionCustomVariableId, string conversionCustomVariableValue)
    {
        // Get the ConversionUploadService.
        ConversionUploadServiceClient conversionUploadService = client.GetService(Services.V11.ConversionUploadService);

        // Create a call conversion by specifying currency as USD.
        CallConversion callConversion = new CallConversion()
        {
            CallerId = callerId,
            CallStartDateTime = callStartTime,
            ConversionDateTime = conversionTime,
            ConversionValue = conversionValue,
            CurrencyCode = "USD"
        };

        if (conversionCustomVariableId != null &&
            !string.IsNullOrEmpty(conversionCustomVariableValue))
        {
            callConversion.CustomVariables.Add(new CustomVariable()
            {
                ConversionCustomVariable = ResourceNames.ConversionCustomVariable(
                    customerId, conversionCustomVariableId.Value),
                Value = conversionCustomVariableValue
            });
        }

        UploadCallConversionsRequest request = new UploadCallConversionsRequest()
        {
            CustomerId = customerId.ToString(),
            Conversions = { callConversion },
            PartialFailure = true
        };

        try
        {
            // Issues a request to upload the call conversion. The partialFailure parameter
            // is set to true, and validateOnly parameter to false as required by this method
            // call.
            UploadCallConversionsResponse response = conversionUploadService.UploadCallConversions(request);

            // Prints the result.
            CallConversionResult uploadedCallConversion = response.Results[0];
            Console.WriteLine($"Uploaded call conversion that occurred at " +
                $"'{uploadedCallConversion.CallStartDateTime}' for caller ID " +
                $"'{uploadedCallConversion.CallerId}' to the conversion action with " +
                $"resource name '{uploadedCallConversion.ConversionAction}'.");
        }
        catch (GoogleAdsException e)
        {
            Console.WriteLine("Failure:");
            Console.WriteLine($"Message: {e.Message}");
            Console.WriteLine($"Failure: {e.Failure}");
            Console.WriteLine($"Request ID: {e.RequestId}");
            throw;
        }
    }
}

}

Also, the error happens on this line...

ConversionUploadServiceClient conversionUploadService = client.GetService(Services.V11.ConversionUploadService);

Any progress on the above?

Could you perhaps delete the bin and obj folders? And the contents of the package folders? I can do a dotnet restore to generate those contents.

Also, what version of Visual Studio are you using? What version of .NET? What type of project is this?

I will get he bin and obj cleanup done and try again in a bit. I am using VS 2019 Enterprise and this project is a console app using .NET 4.7.2.

I cleared the bin and obj and ran the dotnet restore which stated nothing needed to be done. Still get the same error.

I've attached a demo project. This is made in Visual Studio 2022 Community Edition, and is a Console project that targets .NET 4.7.2.

To run,

  1. Unzip into a folder (e.g. C:\Temp)
  2. C:\> cd C:\Temp\ResolveDeps\ResolveDeps
  3. C:\Temp\ResolveDeps\ResolveDeps> nuget restore -SolutionDirectory .. ResolveDeps.csproj
  4. Fill up the contents of App.config
  5. Set your customerId in Program.cs.
  6. C:\Temp\ResolveDeps\ResolveDeps> msbuild ResolveDeps.csproj
  7. C:\Temp\ResolveDeps\ResolveDeps> .\bin\Debug\ResolveDeps.exe

Let me know if this reproduces the issue at your end. Then compare it with the csproj that you created at your end and let me know how they differ.

ResolveDeps.zip

I got the project and I will try a bit later today, but one thing to note, that project runs the GET method for campaigns and I am trying to POST to conversions. So, the line I get an error on is building the "ConversionUploadServiceClient" object and this project uses the "GoogleAdsServiceClient" object instead. So, different classes all together. But, I will try and report back.

Well, I loaded the project you sent and did a "Restore NuGet Packages" which said everything was there, but I get this error when trying to compile it. And the file it says is missing IS there.

This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Grpc.Core.2.41.0\build\net45\Grpc.Core.targets.

How does your directory structure look like? Which directory are you running commands from?

The project is in... C:\Users\shawn.camner\Desktop\Google\ResolveDeps\ResolveDeps

So, basically I unzipped the project to my desktop. Is there something I need to install on the computer or something?

I was able to obtain a failing project from another source. tl;dr; you need to downgrade the following dependencies

  <package id="Google.Api.Gax" version="4.0.0" targetFramework="net472" />
  <package id="Google.Api.Gax.Grpc" version="4.0.0" targetFramework="net472" />
  <package id="Google.Api.Gax.Rest" version="4.0.0" targetFramework="net472" />
  <package id="Google.LongRunning" version="3.0.0" targetFramework="net472" />

to

  <package id="Google.Api.Gax" version="3.7.0" targetFramework="net472" />
  <package id="Google.Api.Gax.Grpc" version="3.7.0" targetFramework="net472" />
  <package id="Google.Api.Gax.Rest" version="3.7.0" targetFramework="net472" />
  <package id="Google.LongRunning" version="2.3.0" targetFramework="net472" />

Make sure you also do this in your App.config just in case Visual Studio doesn't automatically do it for you. A typical binding redirect looks like this:

<dependentAssembly>
  <assemblyIdentity name="Google.Api.Gax" publicKeyToken="3ec5ea7f18953e47" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-3.7.0.0" newVersion="3.7.0.0" />
</dependentAssembly>

The longer explanation is that Google.Api.Gax did a refactoring recently to choose between Grpc.Core (on .NET 472) and Grpc.Net.Client (on .NET 5+/.NET Standard 2.0+). This is backwards-incompatible, so the team did a major version bump. While the Cloud libraries have moved to this new version, Google.Ads.GoogleAds hasn't. This is because the Ads package uses grpc in a slightly more customized way than the Cloud packages, and needs additional testing and benchmarks to ensure all works well.

The error manifests when trying to create any service. The error looks like this:

Method not found: 'Void Google.Api.Gax.Grpc.ClientHelper..ctor(Google.Api.Gax.Grpc.ServiceSettingsBase)'.

In reality, this is an issue about failing to resolve a Channel implementation from Grpc.Net.Client, but since debug symbols are not present, it manifests as a MethodNotFound instead.

For now, please downgrade the Cloud dependencies; we will prioritize this work for Q3 2022.

Well, one step forward, but back to the original issue I was getting when I was using version 11 of the Google Ads library.

Getting this error...

Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1656551760.035000000","description":"Failed to pick subchannel","file":"......\src\core\ext\filters\client_channel\client_channel.cc","file_line":3218,"referenced_errors":[{"created":"@1656551760.035000000","description":"failed to connect to all addresses","file":"......\src\core\lib\transport\error_utils.cc","file_line":165,"grpc_status":14}]}")

Oh, well, it looks like downgrading the libraries also wiped the settings from my config file, so let me get those back and try again. Tomorrow....

Well, so much for tomorrow, I got the values, plugged them in and I still get that same error. I disconnected from my VPN to remove any possible issues with that and tried again, but still get the same.

Since this got resolved offline, I'll close this issue.