c# - Azure Function 和 Docker 出现错误

标签 c# azure docker azure-functions

我正在尝试为 Azure Functions 实现 ICS 创建者示例:https://github.com/Azure-Samples/azure-functions-create-ics-file-using-csharp-sample

我遵循了那里的所有步骤,但与我的实现不同的是,我使用 Docker 在本地运行该函数,并且收到此错误:

An unhandled exception occurred while processing the request.

CompilationErrorException: Script compilation failed. Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker+d__26.MoveNext() in DotNetFunctionInvoker.cs, line 313

FunctionInvocationException: Exception while executing function: Functions.swinvite System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

据我了解,该错误与 ical.net 库有关,该库未导入到图像中。 有任何想法吗?

提前谢谢您。

最佳答案

你是对的,错误与Ical.net库有关。您可以尝试this repository .

更多详情

您遵循的指导是在函数运行时1.x(.net框架)中创建函数,其中将根据project.json恢复包。但是你想使用docker运行(镜像使用runtime 2.x,基于.net core),其中project.json无效。所以可以删除该文件。

然后我们必须手动添加Ical.Net相关程序集。我们可以下载latest version package因为该指南中的指南已经过时了。

下载安装包后,在~\GetInvite下创建一个bin文件夹。将 Ical.Net.dllNodaTime.dll(Ical.Net 的依赖项)复制到此文件夹。

以及 run.csx 中的一些更改。

// add assembly
#r "Ical.Net.dll"

// remove some unnecessary namespaces
using System.Net;
using System.Net.Http.Headers;
using System.Text;
using Ical.Net;
using Ical.Net.DataTypes;
using Ical.Net.CalendarComponents;
using Ical.Net.Serialization;

// remove async as the method has no await method
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log)
{
    ... // remain the same
    // Event is deprecated in new version, use CalendarEvent
    var icalevent = new CalendarEvent{...}
    ... // remain the same
}

还有一点,在function.json中将authLevelfunction更改为anonymous。否则你会得到 401 错误。

关于c# - Azure Function 和 Docker 出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50321468/

相关文章:

php - 没有来自 docker 容器的 php-fpm 错误日志

c# - 如何从文档中的特定位置读取表格?

c# - 如何从 C# 中存储为对象的 object[] 进行转换

azure - Kusto 查询语言 : set column name of summarize by evaluated expression

javascript - Azure表存储的插入功能中查询其他表

docker - 如何更改docker镜像存储的dir root

docker - 从Redmine容器发送邮件

c# - 无法连接到vb.net中的数据库

c# - Func<Owned<T>> 与 Func<T> 依赖关系

azure - 无法连接到 azure 虚拟机。信用SSP问题