2
votes

I am trying to implement the ICS creator sample for Azure Functions: https://github.com/Azure-Samples/azure-functions-create-ics-file-using-csharp-sample.

I followed all the steps there, but the difference with my implementation is that I'm running the function locally with Docker, and I am getting this error:

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()

Per my understanding, the error is related with the ical.net library, that is not being imported to the image. Any ideas?

Thank you in advance.

1

1 Answers

2
votes

You are right, error is related to Ical.net library. You can try this repository.

More details

The guide you follow is to create function in function runtime 1.x(.net framework), where packages will be restored according to project.json. But you want to run using docker(image uses runtime 2.x, based on .net core), where project.json is invalid. So the file can be dropped.

Then we have to add Ical.Net related assemblies manually. We can download latest version package as the one in that guide is out of date.

After downloading the package, create a bin folder under ~\GetInvite. Copy Ical.Net.dll and NodaTime.dll(dependency of Ical.Net) to this folder.

And some changes in 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
}

One more point, in function.json change authLevel from function to anonymous. Or you will get 401 error.