gpt4 book ai didi

c# - Azure 表 : Unable to load one or more of the requested types. 检索 LoaderExceptions 属性以获取更多信息

转载 作者:行者123 更新时间:2023-12-03 03:00:33 25 4
gpt4 key购买 nike

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

当我注释掉除 Table Entity 子类之外的所有代码时,我发现了这一点。这是给我一个异常(exception)的代码。

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

最佳答案

Is there a way to look at the LoaderException stacktrace.

您可以使用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;
}
}

At the moment, Under Property of the Project, Application -> Target Framework is running in .netStandard 2.0

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

enter image description here

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

创建 Azure function 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 is in preview, and currently not all features of Azure Functions are supported.

关于c# - Azure 表 : Unable to load one or more of the requested types. 检索 LoaderExceptions 属性以获取更多信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49289848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com