gpt4 book ai didi

c# - 无法从程序集“System.Runtime,版本=4.2.2.0,文化=中性”加载类型 'System.Runtime.CompilerServices.AsyncVoidMethodBuilder'

转载 作者:行者123 更新时间:2023-12-03 01:19:31 27 4
gpt4 key购买 nike

我有一个 azure 函数应用程序,它依赖于另一个类库来完成某些功能。

Azure 功能详细信息:目标框架:net5.0AzureFunctions版本:v3

类库详细信息:目标框架:net5.0

我在AzureFunction中引用了类库项目。

Azure 函数代码:

Startup.cs:

[assembly: FunctionsStartup(typeof(Startup))]
namespace MessageReceiver
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddTransient<IMailSender, MailSender>();
}
}
}

MessageReceiver.cs

namespace ProcessReportRequests
{
public class MessageReceiverDataFunction
{
private const string QUEUE_NAME = "message-queue";
private readonly IMailSender _mailSender;
private readonly ILogger<MessageReceiverDataFunction> _log;
public MessageReceiverDataFunction(IMailSender mailSender, ILogger<MessageReceiverDataFunction> log)
{
_mailSender = mailSender ?? throw new ArgumentNullException(nameof(mailSender));
_log = log ?? throw new ArgumentNullException(nameof(log));
}

[FunctionName("MessageReceiver")]
public void Run([QueueTrigger(QUEUE_NAME, Connection = "StorageConnectionString")] string queueMessage)
{
_mailSender.SendPlaintextMail("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c21356238293f380c2b212d2520622f2321" rel="noreferrer noopener nofollow">[email protected]</a>", "mytest");
_log.LogInformation($"C# Queue trigger function processed: {queueMessage}");
}
}
}

类库:ReportUtility

IMailSender.cs:

public interface IMailSender
{
void SendPlaintextMail(string recipientEmail, string recipientName);
}

MailSender.cs

public class MailSender : IMailSender
{
public MailSender()
{
}

public async void SendPlaintextMail(string recipientEmail, string recipientName)
{
var sender = new SmtpSender(() => new SmtpClient("xxx.yyyy.zzzz")
{UseDefaultCredentials = false, Port = 10, Credentials = new NetworkCredential(recipientEmail, "xxxxxxxxxxxxxx"), EnableSsl = true, });
Email.DefaultSender = sender;
var email = await Email.From(emailAddress: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff9286d18b9a8c8bbf8c9a919b9a8d929e9693d19c9092" rel="noreferrer noopener nofollow">[email protected]</a>").To(emailAddress: recipientEmail, name: recipientName).Subject(subject: "Testing Email Subject").Body(body: "This is a plain text message").SendAsync();
}
}

在测试应用程序时,我收到如下错误:

2022-05-11T19:53:58.654 [Error] Executed 'MessageReceiver' (Failed, Id=f13f0402-7c74-4f39-a9e1-a65fa8f61af9, Duration=3ms)Could not load type 'System.Runtime.CompilerServices.AsyncVoidMethodBuilder' from assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

任何人都可以提供解决此问题的指导

最佳答案

为避免这种情况,请尝试将函数应用更新到版本 4。

将以下项目值更新为:

<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>

并使用此命令:

az functionapp config appsettings set --settings FUNCTIONS_EXTENSION_VERSION=~4 -n <APP_NAME> -g <RESOURCE_GROUP_NAME>

引用:
Migrating from 3.x to 4.x ,
.NET Core 3.1 - Could not load file or assembly System.Runtime, Version=4.2.2.0

关于c# - 无法从程序集“System.Runtime,版本=4.2.2.0,文化=中性”加载类型 'System.Runtime.CompilerServices.AsyncVoidMethodBuilder',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72207030/

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