【问题标题】:Azure table: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more informationAzure 表:无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息
【发布时间】:2018-08-23 16:43:53
【问题描述】:

我收到一条错误消息,提示“无法加载一种或多种请求的类型。检索显示在 Func.exe 命令提示符内的更多信息的 LoaderExceptions 属性。

我在注释除具有表实体子类的代码之外的所有代码时发现。那就是代码给我一个例外。

public class RollCallHistoryEntity : TableEntity
{
    public RollCallHistoryEntity() { }

    public RollCallHistoryEntity(RollCallTransaction transaction)
    {
        this.PartitionKey = Convert.ToString(transaction.OrgId);
        this.RowKey = Guid.NewGuid().ToString();

        this.OrgId = transaction.OrgId;
        this.AttendanceId = transaction.AttendanceId;
        this.ActionId = transaction.ActionId;
        this.HappenedOn = transaction.HappenedOn;

public static class Function1
{
    [FunctionName("Function1")]
    public static async Task Run([QueueTrigger("queue-trigger", Connection = "tuxdev_STORAGE")]string myQueueItem, TraceWriter log)
    {
        log.Info($"C# Queue trigger function processed: {myQueueItem}");

        var queueItem = JsonConvert.DeserializeObject<RollCallTransaction>(myQueueItem);
        //var historyTable = await Azure.AzureTable.GetTable(Azure.AzureTable.TABLE_ROLLCALL_HISTORY);
        //var historyEntity = new Azure.Entity.RollCallHistoryEntity(queueItem);
    }
}

不用担心 RollCallProcessor,这是我的旧项目。我用上面的代码重新创建了一个新项目,但仍然有同样的问题。

【问题讨论】:

  • 如果你能提供有关 RollCallProcessor 的代码,那会更有帮助。这是一个类似的article,看来是.NET Framework版本的问题。
  • 有没有办法查看 LoaderException 堆栈跟踪。
  • 也许您可以捕获异常以获取更多信息。
  • 对我来说,当我依赖一个 x64 项目时发生了这个异常。我找不到实际读取 LoaderExceptions 属性的方法,但解决方案是在 x64 主机中运行函数,使用这篇文章:henkboelman.com/azure-function-x64-dev-setup

标签: c# azure azure-functions azure-table-storage


【解决方案1】:

有没有办法查看 LoaderException 堆栈跟踪。

您可以使用StackTrace 类来跟踪项目中的异常。

或者您可以检索 ReflectionTypeLoadException.LoaderException 属性以获取有关 LoaderException 的更多信息。

捕捉Code中的异常:

try
{
  // load the assembly or type
}
catch (Exception ex)
{
  if (ex is System.Reflection.ReflectionTypeLoadException)
  {
    var typeLoadException = ex as ReflectionTypeLoadException;
    var loaderExceptions  = typeLoadException.LoaderExceptions;
  }
}

目前,在项目的属性下,应用程序 -> 目标框架在 .netStandard 2.0 中运行

只有触发器类型中的一些功能可以在 Azure 函数 v2 预览版模板中使用:

例如,BlobTrigger 在 v2 中支持良好。您可以尝试操作 azure storage。

创建 Azure 函数 v2 预览:

创建 BlobTrigger:

BlobTrigger 中的代码:

public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([BlobTrigger("helloworld/{name}", Connection = "AzureWebJobsStorage")]Stream myBlob, string name, TraceWriter log)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
   "storage account connection string");
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("helloworld");
            CloudAppendBlob blob = container.GetAppendBlobReference("log2.txt");
            using (var fileStream = System.IO.File.OpenRead(@"D:\log.txt"))
            {
                blob.UploadFromStreamAsync(fileStream);
            }
            log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        }

}

BlobTrigger 中的结果:

所以你最好选择兼容的平台版本。更多详情请参考article

Azure Functions 运行时 2.0 处于预览阶段,目前并非支持 Azure Functions 的所有功能。

【讨论】:

  • 我不知道发生了什么...目前,我尝试引用收到的 Azure 表无法加载文件或程序集 'Microsoft.WindowsAzure.Storage,版本 = 8.6。 0.0,文化=中性,PublicKeyToken=31bf3856ad364e35'。无法找到或加载特定文件。 (来自 HRESULT 的异常:0x80131621)。但我确实添加了一个带有 8.6.0 WindowsAzure.Storage 的包。
  • 我已经添加了 nugget 包 .nET.sdk.Functions 包 1.0.9 和 Storage 包。 .Net.SDK.Funtiions 使用的是 Storage 8.6.0 而不是 9.1.0
  • 如果我将 Microsoft.WindowsAzure.Storage 的 nugget 包安装到 9.1.0,会出现一些奇怪的情况,错误是一样的。甚至卸载后,编译没有问题,但函数仍然运行同样的错误。
  • 你的.net框架版本怎么样。检查Microsoft.NET.Sdk.Functions nuget 包中依赖项的兼容性。似乎WindowAzure.Storage 已经在这个包中。您无需再次添加单独的包。
  • 目前,在项目属性下,Application -> Target Framework 正在.netStandard 2.0中运行
猜你喜欢
  • 1970-01-01
  • 2011-04-18
  • 1970-01-01
  • 2010-11-08
  • 2016-10-03
  • 1970-01-01
相关资源
最近更新 更多