【问题标题】:Dynamics NAV could not load assembly or fileDynamics NAV 无法加载程序集或文件
【发布时间】: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


    【解决方案1】:

    您可以使用Process Monitor 来识别找不到的库。按进程名称和结果代码过滤捕获的事件(它将是“未找到路径”,指的是导航加载项文件夹中的路径)。 找到库后,您可以将其复制到加载项位置或动态加载 (How to load assemblies into an application domain)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-17
      相关资源
      最近更新 更多