c# - Azure函数 "Unable to find assembly"

标签 c# .net azure nuget azure-functions

我一直在尝试适用于 Azure Functions 的新 Visual Studio 2017 工具,但遇到了问题。

当尝试在 Azure 函数中从 Nuget 包 PowerOfficeGoSDK 初始化类时,我收到 SerializationException:

var authorizationSettings = new AuthorizationSettings
{
    ApplicationKey = applicationKeyGuid,
    ClientKey = clientKeyGuid,
    TokenStore = new BasicTokenStore("my.tokenstore")
};

var goApi = new Go(authorizationSettings);

System.Runtime.Serialization.SerializationException : Unable to find assembly 'GoApi, Version=1.5.1.0, Culture=neutral, PublicKeyToken=null'.

该代码使用各种其他 Nuget 包(例如 Microsoft.Azure.KeyVault),没有任何问题。我使用 Kudu 检查了该函数的 bin 文件夹,GoApi.dll 文件就在那里。

有人知道什么可能导致异常吗?

最佳答案

我对PowerOfficeGoSDK不太熟悉,但根据我的测试,PowerOfficeGoSDK可以加载到Azure函数中。如果可以的话,请尝试重新发布或者创建一个新的功能App来再次测试。

以下是我的详细步骤:

1.使用Visual studio 2017创建新的Azure函数项目

2.根据PowerOfficeGoSDK Dependency,我们需要将newtonsoft.json和Microsoft.Data.Edm更新到以下版本

Microsoft.Data.Edm (>= 5.8.2) 
Newtonsoft.Json (>= 10.0.2) 

注意:有关于在 Azure 函数中使用 Newtonsoft.Json 版本 10+ 的 an issue

3.添加timetrigger功能,并在local.settings.json文件中配置存储连接字符串。

[FunctionName("AzureFunction")]
public static void Run([TimerTrigger("0 */2 * * * *")]TimerInfo myTimer, TraceWriter log)
{
    log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
    try
      {
         var authorizationSettings = new AuthorizationSettings
         {
            ApplicationKey = Guid.NewGuid().ToString(), //I have no application key
            ClientKey = Guid.NewGuid().ToString(), //I have no client key
            TokenStore = new BasicTokenStore("my.tokenstore")
          };
          var goApi = new Go(authorizationSettings);
        }
        catch (Exception e)
        {
           log.Info($"Exception:{e.Message}"); 
        }

        log.Info($"C# Timer trigger function Finished at: {DateTime.Now}");
}

4.使用Visual Studio将其发布到Azure并在Azure门户中检查结果。

注意:我没有应用程序和客户端 key ,因此我收到异常Invalid ApplicationKey or ClientKey,它与预期一样。

enter image description here

关于c# - Azure函数 "Unable to find assembly",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45843071/

相关文章:

java - 这两种方法一起是一种递归形式吗?

c# - 为什么 IsWellFormedOriginalString 在文件 Uris 上失败?

Azure DevOps - Octopus 的打包应用程序 : System. IO.IOException:参数不正确 *

asp.net - Azure 上的联合身份验证

azure - 使用 Bicep 创建 Azure 资源组

c# - 出现问题时如何引发异常?

c# - 使 StructLayout 在类上工作,就像它在结构上工作一样

.net - 限制进程使用的处理器数量

c# - 循环后台任务

c# - 如何在 EF Code First 中创建/更新 LastModified 字段