我正在尝试为 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.dll
和 NodaTime.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
中将authLevel
从function
更改为anonymous
。否则你会得到 401 错误。
关于c# - Azure Function 和 Docker 出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50321468/