首页 文章

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

提问于
浏览
1

我有一个错误说'无法加载一个或多个请求的类型 . 检索LoaderExceptions属性以获取更多信息'显示在Func.exe命令提示符内 .

当我评论除了具有Table Entity子类的代码之外的所有代码时,我发现了 . 那是代码给我一个例外 .

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;

enter image description here

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

1 回答

  • 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 function v2 preview 模板中使用:

    enter image description here

    例如,BlobTrigger支持v2中的罚款 . 您可以尝试操作azure存储 .

    创建Azure功能v2预览:

    enter image description here

    创建BlobTrigger:

    enter image description here

    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中的结果:

    enter image description here

    因此,您最好选择兼容的平台版本 . 更多细节请参考article .

    Azure Functions runtime 2.0处于预览状态,目前并不支持Azure功能的所有功能 .

相关问题