【发布时间】:2015-09-18 12:05:01
【问题描述】:
我在 C# 中创建了一个类库,我将其用作 Dynamics NAV 中的加载项,以获取我在 Google Drive 中的文件的文件 ID。为此,我使用 Google C# API。 当我从 Visual Studio 运行代码时,我没有收到任何错误,但是当我从 RoleTailored Client 运行它时,我收到以下错误:
微软动态导航
对 GoogleDriveAPI.Program.SetCredential 的调用失败并显示以下消息:无法加载文件或程序集 'Google.Apis.Auth,版本=1.9.2.27817,文化=中性, PublicKeyToken=4b01fa6e34db77ab' 或其依赖项之一。这 系统找不到指定的文件。
我猜是因为我的类的 .dll 版本没有引用 .dll 'Google.Apis.Auth',但我不确定。
这是我的代码:
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace GoogleDriveAPI
{
public class Program
{
private static string[] Scopes = { DriveService.Scope.DriveReadonly };
private static string ApplicationName = "Google Drive Get FileID";
private static UserCredential credential;
private static string FileId;
public void SetCredential(string credPath)
{
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) {
credPath = Path.Combine(credPath, ".credentials");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
}
public string GetFileId()
{
// Create Drive API service.
var service = new DriveService(new BaseClientService.Initializer() {
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define parameters of request.
FilesResource.ListRequest listRequest = service.Files.List();
listRequest.MaxResults = 1;
// List files.
IList<Google.Apis.Drive.v2.Data.File> files = listRequest.Execute().Items;
Console.WriteLine("Files:");
if (files != null && files.Count > 0) {
foreach (var file in files) {
Console.WriteLine("{0} ({1})", file.Title, file.Id);
FileId = file.Id;
}
return FileId;
} else {
return null;
}
}
}
}
执行GoogleWebAuthorizationBroker.AuthorizeAsync() 方法时发生错误。
【问题讨论】:
标签: c# dll add-in microsoft-dynamics navision