加载google . api .dll给了我StackoverflowException

本文关键字:StackoverflowException dll google api 加载 | 更新日期: 2023-09-27 18:10:07

我在使用ExcelDna构建的Excel插件中添加新的Google Analytics api时遇到了麻烦。

我已经添加了这些Nugets:

  <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" />

如果我创建一个类:

public class Foo {
 public Foo() {
    AnalyticsService bar = null;
 }
}

一旦我尝试创建这个类的实例,我得到一个StackoverflowException。

所以我猜这是谷歌api程序集加载的问题?

使用FusionLog我可以看到google . api . analytics .v3.dll加载正常,但在google . api .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.

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

现在我被卡住了。下一步该怎么做?

更新

我更新了NetOffice,去掉了stackoverflowexception。现在我得到了这个异常:

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)

加载google . api .dll给了我StackoverflowException

您唯一应该导入的是

PM> Install-Package google . api . analytics。v3

我测试了你发布的代码,它没有给我一个错误。

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

Oauth2示例与Google 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#教程

相关文章:
  • 没有找到相关文章