Google.Protobuf.dll is right next to my .dll but it is not being found or loaded

560 views
Skip to first unread message

Bruce Axtens

unread,
Jul 13, 2022, 9:48:29 PM7/13/22
to Google Ads API and AdWords API Forum

I have a Framework 4.8 C# app that uses ClearScript to allow JavaScript to be used as an extension language. I am able to write plugins as DLLs and attach them at runtime with code like:

attach(".\\Plugin_GoogleAds_Metrics.dll"); 
var H = Plugin_GoogleAds_Metrics.GoogleAds_Metrics.Historical;
var auths = H.AuthoriseFromCFG(cfg,"7212153394");
var acc = H.GetAccountInformation(auths.Item1, 7273576109, true);

The C# code I'm using for the attach is 

JSE.Script.attach = (Func<string, bool>)Attach;

...

private static bool Attach(string dllPath, string name = "")
{
    var status = false;
    var htc = new HostTypeCollection();
    try
    {
        var assem = Assembly.Load(AssemblyName.GetAssemblyName(dllPath));
        htc.AddAssembly(assem);
        if (name.Length == 0)
        {
            name = assem.FullName.Split(',')[0];
        }

        JSE.AddHostObject(name, htc); //FIXME checkout the hosttypes
        Console.Error.WriteLine($"Attached {dllPath} as {name}");
        status = true;
    }
    catch (ReflectionTypeLoadException rtle)
    {
        foreach (var item in rtle.LoaderExceptions)
        {
            Console.Error.WriteLine(item.Message);
            T.Fail(item.Message);
        }

    }
    catch (FileNotFoundException fnfe)
    {
        Console.Error.WriteLine(fnfe.Message);
        T.Fail(fnfe.Message);

    }
    catch (Exception e)
    {
        Console.Error.WriteLine(e.Message);
        T.Fail(e.Message);

    }
    return status;
}

The plugin code FWIW (which isn't much) is at <https://github.com/axtens/Plugin_GoogleAds_Metrics>

What's not working in this situation is that when I try to execute the plugin's GetAccountInformation method, and execution reaches the GoogleAdsServiceClient googleAdsService = client.GetService(Services.V11.GoogleAdsService); line, an error is thrown complaining about Google.Protobuf, viz

Exception has been thrown by the target of an invocation. at JScript global code (Script [23] [temp]:5:0) -> acc = H.GetAccountInformation(auths.Item1, 7273576109, true) at Microsoft.ClearScript.ScriptEngine.ThrowScriptError(IScriptEngineException scriptError) at Microsoft.ClearScript.Windows.WindowsScriptEngine.ThrowScriptError(Exception exception) at Microsoft.ClearScript.Windows.WindowsScriptEngine.<>c__DisplayClass57_0`1.<ScriptInvoke>b__0() at Microsoft.ClearScript.ScriptEngine.ScriptInvokeInternal[T](Func`1 func) at Microsoft.ClearScript.ScriptEngine.ScriptInvoke[T](Func`1 func) at Microsoft.ClearScript.Windows.WindowsScriptEngine.ScriptInvoke[T](Func`1 func) at Microsoft.ClearScript.Windows.WindowsScriptEngine.Execute(UniqueDocumentInfo documentInfo, String code, Boolean evaluate) at Microsoft.ClearScript.Windows.JScriptEngine.Execute(UniqueDocumentInfo documentInfo, String code, Boolean evaluate) at Microsoft.ClearScript.ScriptEngine.Evaluate(UniqueDocumentInfo documentInfo, String code, Boolean marshalResult) at Microsoft.ClearScript.ScriptEngine.Evaluate(DocumentInfo documentInfo, String code) at Microsoft.ClearScript.ScriptEngine.Evaluate(String documentName, Boolean discard, String code) at Microsoft.ClearScript.ScriptEngine.Evaluate(String documentName, String code) at Microsoft.ClearScript.ScriptEngine.Evaluate(String code) at RulesetRunner.Program.Run(JScriptEngine& jSE, String scriptText, Config cfg, Dictionary`2 settings) in C:\Users\bugma\Source\Repos\Present\BORR\RulesetRunner\RunManagementPartials.cs:line 72 Exception has been thrown by the target of an invocation. Exception has been thrown by the target of an invocation. Could not load file or assembly 'Google.Protobuf, Version=3.15.8.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604' or one of its dependencies. The system cannot find the file specified.

So

  1. I am using the latest Google.Ads.GoogleAds library
  2. AutoGenerateBindingRedirects has been set to true in the csproj file
  3. Add-BindingRedirect has been executed in the context of the Plugin's project
  4. The Plugin_GoogleAds_Metrics.dll is in the same folder as the Google.Protobuf.dll

How is it that "The system cannot find the file specified."? And where do I go from here?

-- Bruce

Google Ads API Forum Advisor

unread,
Jul 14, 2022, 12:26:57 AM7/14/22
to bru...@searchsmart.com.au, adwor...@googlegroups.com
Hi Bruce,

Thank you for posting your concern.

Upon checking the issue, it appears the issue is more specific with the client library. With this, I would suggest raising your concern to this github issue tracker issue to get insights from the author of .Net client library. They are more equipped to deal with this matter.

Regards,
Google Logo
Ernie John
Google Ads API Team
 


ref:_00D1U1174p._5004Q2cVujP:ref
Reply all
Reply to author
Forward
0 new messages