Azure table:无法加载一种或多种请求的类型。检索 LoaderExceptions 属性 以获取更多信息

Azure table: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information

我在 Func.exe 命令提示符中显示 'Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information' 时出错。

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

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,它是我的旧项目。我用上面的代码重新创建了一个新项目,但仍然有同样的问题。

Is there a way to look at the LoaderException stacktrace.

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

或者您可以检索 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;
  }
}

At the moment, Under Property of the Project, Application -> Target Framework is running in .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 runtime 2.0 is in preview, and currently not all features of Azure Functions are supported.