2015-08-28 23 views
1

我无法将新的Google AnalyticsAPI添加到我使用ExcelDna构建的Excel加载项中。当我尝试创建这个类我得到一个StackoverflowException的实例加载Google.Apis.dll给我StackoverflowException

public class Foo { 

public Foo() { 
    AnalyticsService bar = null; 
} 

} 

:如果我创建一个类

<package id="Google.Apis" version="1.9.3" targetFramework="net45" /> 
    <package id="Google.Apis.Analytics.v3" version="1.9.2.1160" targetFramework="net45" /> 
    <package id="Google.Apis.Auth" version="1.9.3" targetFramework="net45" /> 
    <package id="Google.Apis.Core" version="1.9.3" targetFramework="net45" /> 

我已经添加了这些Nugets。

所以我猜这是加载Google Apis程序集的问题?

使用FusionLog我可以看到Google.Apis.Analytics.v3.dll加载好了,但在Google.Apis.DLL有一个问题:

*** Assembly Binder Log Entry (2015-08-27 @ 14:12:32) *** 

The operation failed. 
Bind result: hr = 0x80131040. No description available. 

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll 
Running under executable C:\Program Files\Microsoft Office\Office14\EXCEL.EXE 
--- A detailed error log follows. 

=== Pre-bind state information === 
LOG: DisplayName = Google.Apis, Version=1.9.2.27817, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab 
(Fully-specified) 
LOG: Appbase = file:///C:/Checkouts/NielsBosma/trunk/projects/SeoTools/bin/Debug 
LOG: Initial PrivatePath = NULL 
LOG: Dynamic Base = NULL 
LOG: Cache Base = NULL 
LOG: AppName = Excel-DNA: C:\Checkouts\NielsBosma\trunk\projects\SeoTools\bin\Debug\SeoTools64.xll 
Calling assembly : Google.Apis.Analytics.v3, Version=1.9.2.116, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab. 
=== 
LOG: This bind starts in default load context. 
LOG: No application configuration file found. 
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. 
LOG: Post-policy reference: Google.Apis, Version=1.9.2.27817, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab 
LOG: GAC Lookup was unsuccessful. 
LOG: Attempting download of new URL file:///C:/Checkouts/NielsBosma/trunk/projects/SeoTools/bin/Debug/Google.Apis.DLL. 
LOG: Assembly download was successful. Attempting setup of file: C:\Checkouts\NielsBosma\trunk\projects\SeoTools\bin\Debug\Google.Apis.dll 
LOG: Entering run-from-source setup phase. 
LOG: Assembly Name is: Google.Apis, Version=1.9.3.19379, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab 
WRN: Comparing the assembly name resulted in the mismatch: Revision Number 
ERR: The assembly reference did not match the assembly definition found. 
ERR: Run-from-source setup phase failed with hr = 0x80131040. 
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated. 

我已经创建了这些包,其中一个控制台应用程序这个问题不存在。

现在我卡住了。接下来做什么?

UPDATE

我更新NetOffice并摆脱了StackoverflowExeception的。现在,我得到这个异常:

Could not load file or assembly 'Google.Apis, Version=1.9.2.27817, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 
+0

撕开是否有可能在控制台应用程序,工作的绑定重定向?也许你可以为其他依赖安装稍旧的1.9.2包(在NuGet命令行上使用显式-Version)。 – Govert

+0

@govert是的,有一个针对“System.Net.Http.Primitives”的绑定重定向,由nuget在app.config中添加,似乎是问题所在。我仅以ExcelDna和Google Analytics Apis的小解决方案再现了这个问题。这个工程的控制台版本。 xll中包含app.config的东西吗? –

+1

您必须在MyAddIn.xll文件旁边创建自己的MyAddin.xll.config文件。我不确定绑定重定向从.xll.config文件将工作。如果您删除.config文件,您的控制台应用程序是否会提供相同的错误? – Govert

回答

0

你应该已经进口的唯一的事情就是

PM> Install-Package Google.Apis.Analytics.v3

我测试你贴和不给我一个错误代码。

public class Foo 
    { 

     public Foo() 
     { 
      AnalyticsService bar = null; 
     } 

    } 

    class Program 
    { 
     static void Main(string[] args) 
     { 
      Foo test = new Foo(); 
     } 
    } 

的oauth2例如与谷歌Analytics(分析)

/// <summary> 
     /// Authenticate to Google Using Oauth2 
     /// Documentation https://developers.google.com/accounts/docs/OAuth2 
     /// </summary> 
     /// <param name="clientId">From Google Developer console https://console.developers.google.com</param> 
     /// <param name="clientSecret">From Google Developer console https://console.developers.google.com</param> 
     /// <param name="userName">A string used to identify a user.</param> 
     /// <returns></returns> 
     public static AnalyticsService AuthenticateOauth(string clientId, string clientSecret, string userName) 
     { 

      string[] scopes = new string[] { AnalyticsService.Scope.Analytics, // view and manage your analytics data 
              AnalyticsService.Scope.AnalyticsEdit, // edit management actives 
              AnalyticsService.Scope.AnalyticsManageUsers, // manage users 
              AnalyticsService.Scope.AnalyticsReadonly};  // View analytics data 

      try 
      { 
       // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData% 
       UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret } 
                          , scopes 
                          , userName 
                          , CancellationToken.None 
                          , new FileDataStore("Daimto.GoogleAnalytics.Auth.Store")).Result; 

       AnalyticsService service = new AnalyticsService(new BaseClientService.Initializer() 
       { 
        HttpClientInitializer = credential, 
        ApplicationName = "Analytics API Sample", 
       }); 
       return service; 
      } 
      catch (Exception ex) 
      { 

       Console.WriteLine(ex.InnerException); 
       return null; 

      } 

     } 

代码从Google Analytics API Authentication with C# tutorial

+0

如果你阅读我的问题,这是我得到的。 –

+1

“只要我尝试创建此类的实例,就会得到一个StackoverflowException。“我创建了这个类,并没有给我一个错误,请发布一个显示错误发生的例子。 – DaImTo