首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure函数v2和system.text.json

Azure函数v2和system.text.json
EN

Stack Overflow用户
提问于 2019-09-13 21:04:15
回答 1查看 770关注 0票数 0

我正在尝试实现一个使用.net核心3(预览版9)作为目标框架并使用新的System.text.json命名空间的函数。下面是我的代码:

代码语言:javascript
复制
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using System.Text.Json;

namespace Backtester
{
    public class Test
    {
        public string Author { get; set; }
        public string Currency { get; set; }
    }

    public static class Function
    {
        [FunctionName("Function")]
        public static void Run([ServiceBusTrigger("%QueueName%", Connection = "AzureWebJobsServiceBus")]string myQueueItem, ILogger log)
        {
            try
            {
                var request = JsonSerializer.Deserialize<Test>(myQueueItem);
                log.LogInformation($"Currency: {request.Currency} - {request.Author}");
            }
            catch (Exception ex)
            {
                throw;
            }
        }
    }
}

当我运行代码并将消息提交到服务总线队列时,函数被触发,但失败,并显示以下错误:

代码语言:javascript
复制
[13/09/2019 13:01:25] System.Private.CoreLib: Exception while executing function: Function. Backtester: Could not load file or assembly 'System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058). Cannot load a reference assembly for execution.
[13/09/2019 13:01:25] MessageReceiver error (Action=UserCallback, ClientId=MessageReceiver1********************, EntityPath=**********, Endpoint=**********************************)
[13/09/2019 13:01:25] System.Private.CoreLib: Exception while executing function: Function. Backtester: Could not load file or assembly 'System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058). Cannot load a reference assembly for execution.

我得出的结论是,我将不得不将我的项目降级到.net核心2.2,这将导致相当多的工作,因为我有一个使用新代码库的web项目。

EN

回答 1

Stack Overflow用户

发布于 2019-11-19 21:33:52

我的解决方案最初是将我的项目降级到.net Core2.2,并使用Netwonsoft的Json.net (v11是Microsoft.AspNetCore.App和SignalR.Core的依赖)。我想补充的是,json.net现在是一个成熟得多的产品,所以从一开始就肯定会推荐这条路线。

从那时起,我实际上已经把我的Azure函数移到了AWS Lambda上,它确实允许你上传一个自定义的运行时,所以如果你想在云中使用.net核心3,你可以这样做。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57924191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档