Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 创建AdWords API服务时,是什么导致TargetInvocationException异常?_C#_Google Ads Api - Fatal编程技术网

C# 创建AdWords API服务时,是什么导致TargetInvocationException异常?

C# 创建AdWords API服务时,是什么导致TargetInvocationException异常?,c#,google-ads-api,C#,Google Ads Api,我正在学习连接到AdWords API。当我尝试使用我的AdWordsUser对象创建服务时,会出现第一个块。我得到了一个TargetInvocationException: Exception has been thrown by the target of an invocation 内部异常: The value of the property 'type' cannot be parsed. The error is: Could not load file or assembly '

我正在学习连接到AdWords API。当我尝试使用我的
AdWordsUser
对象创建服务时,会出现第一个块。我得到了一个
TargetInvocationException

Exception has been thrown by the target of an invocation
内部异常:

The value of the property 'type' cannot be parsed. The error is: Could not
load file or assembly 'Google.Ads.Common, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=52807268f2b614dc' or one of its dependencies. The located
assembly's manifest definition does not match the assembly reference. (Exception
from HRESULT: 0x80131040)
根据我的谷歌搜索,建议的主要修复方法是在app.config中添加对
SoapListenerExtension
的引用。我尝试了两种方法(如问题末尾所示),没有任何改变

我的应用程序包括对
Google.Ads.Common
Google.AdWords
System.Web.Services
库的引用。这是我的代码,通过扩展引用消除歧义

var  headers    = new Dictionary<string, string>();
headers.Add("email", Properties.Settings.Default.AdWordsUserName);
// Rest of the creds
var  _user      = new Google.Api.Ads.AdWords.Lib.AdWordsUser(headers);
var  sig        = Google.Api.Ads.AdWords.Lib.AdWordsService.v201109.CampaignService;
var  rawService = _user.GetService(sig);  // The exception is thrown here
var  service    = (Google.Api.Ads.AdWords.v201109.CampaignService)rawService;
此程序集已加载,似乎已成功加载:

Loaded: Google.Ads.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
…所以看起来我的程序集没有签名。果不其然,有一个API的签名版本可用。令人恼火的是,它的结构与未签名版本不同,并且大多数完全限定名不再有效。回到绘图板上


附录

Web服务方法1:

  <system.web>
    <webServices>
      <soapExtensionTypes>
        <add type="Google.Api.Ads.Common.Lib.SoapListenerExtension, Google.Ads.Common" priority="1" group="0"/>
      </soapExtensionTypes>
    </webServices>
  </system.web>

方法2:

<system.web>
    <webServices>
        <soapExtensionTypes>
            <add type="Google.Api.Ads.Common.Lib.SoapListenerExtension, Google.Ads.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=52807268f2b614dc" priority="1" group="Low"/>
        </soapExtensionTypes>
    </webServices>
</system.web>


将我的引用交换到已签名版本就成功了。回想起来,我认为错误消息相当清楚地指出了这一点。我想知道未签名的版本用于什么,或者换句话说,为什么只有签名的版本在这个实例中工作?

听起来您这里有一个程序集版本问题
<system.web>
    <webServices>
        <soapExtensionTypes>
            <add type="Google.Api.Ads.Common.Lib.SoapListenerExtension, Google.Ads.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=52807268f2b614dc" priority="1" group="Low"/>
        </soapExtensionTypes>
    </webServices>
</system.web>