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.
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.
Related
I am migrating some legacy .Net code from an App Service into an Azure Function triggered by a Service Bus topic. This will run under .Net Framework 4.8 as an Azure function V1. I am running into the error "No job functions found. Try making your job classes and methods public" etc.
To test this, I created a brand new Azure function using the Visual Studio 2022 template, and it does not have this warning. However, looking at the NuGet packages, I can see that the template installs Microsoft.Azure.WebJobs.ServiceBus, which is deprecated.
I removed that package and installed the new Microsoft.Azure.WebJobs.Extensions.ServiceBus package that is recommended.
The only change to the code that I had to make was to remove the AccessRights attribute, since that's not supported any more.
Now, when I run the Azure Function, I get the "No job functions found" warning.
The warning suggests that I am supposed to call config.UseServiceBus() somewhere. I've seen from some questions on this where people do this in Program.cs in the Main function. However, this is a DLL library project, so there is no Program.cs or startup code.
I've looked for a Migration Guide and searched for similar problems, but everything I've found is for .Net 5, not Framework 4.8.
What is the correct way to initialize a .Net48 Azure Function built as a DLL? Should I convert this project to a Console Program instead, and initialize in Main()?
Edit:
This is the template-generated function that works before updating the library:
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.ServiceBus.Messaging;
namespace AFTest
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([ServiceBusTrigger("testtopic", "testsubscription", AccessRights.Listen, Connection = "ServiceBusConnectionString")]string mySbMsg, TraceWriter log)
{
log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
}
}
}
Here's the slightly modified code (removing the Access attribute) that doesn't work:
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
namespace AFTest
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([ServiceBusTrigger("testtopic", "testsubscription", Connection = "ServiceBusConnectionString")]string mySbMsg, TraceWriter log)
{
log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
}
}
}
I try to create a database in the local cosmosDB emulator but this fails to work. It throws an exception with the following message:
Response status code does not indicate success: InternalServerError
(500); Substatus: 0; ActivityId: 36f6a95d-26d7-4ecd-9c81-f6df220f3cdc;
Reason: (Unknown server error occurred when processing this request.
ActivityId: 36f6a95d-26d7-4ecd-9c81-f6df220f3cdc,
Microsoft.Azure.Documents.Common/2.14.0,
Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum,
Windows/10.0.19042 cosmos-netstandard-sdk/3.24.1);
This error happens in my project as well as in an simple, empty console app only containing these lines of code:
using Microsoft.Azure.Cosmos;
namespace CosmosDBTest;
class Program
{
public static async Task Main()
{
using var client = new CosmosClient("<A local connection string>");
var response = await client.CreateDatabaseIfNotExistsAsync("test", 500);
var database = response.Database;
await database.CreateContainerIfNotExistsAsync("container1", "id");
}
}
The version of the emulator I use is 2.14.6. The version of the NuGet package is 3.26.1
What is causing this exception and how do I solve this? I has worked with older versions of the emulator in combination of an older version of the NuGet package. But before I downgrade the emulator and/or package, I want to find out if there is a better work around.
I haven't tried the demo application which is offered by the emulator. Funny enough as it is on a tab with the name ".NET" (and another tab .NET core next to it) the ".NET" example is written in the very old version .net core 2.1 which I don't have installed even.
Try resetting the Emulator, this looks like a malfunction on the Emulator itself. The HTTP 500 is coming from the Emulator, the SDK is just surfacing the response.
Reference: https://learn.microsoft.com/azure/cosmos-db/troubleshoot-local-emulator
If you installed a new version of the emulator and are experiencing errors, ensure you reset your data. You can reset your data by right-clicking the Azure Cosmos DB Emulator icon on the system tray, and then clicking Reset Data…. If that does not fix the errors, you can uninstall the emulator and any older versions of the emulator if found, remove C:\Program files\Azure Cosmos DB Emulator directory and reinstall the emulator.
Alternatively if resetting the data doesn't work, navigate to %LOCALAPPDATA%\CosmosDBEmulator location and delete the folder.
I published my c# .NET 5.0 code to azure functions (windows) and im getting this weird error message:
2021-06-21T01:56:53.465 [Error] Executed 'Function1' (Failed, Id=fdefdbba-49a7-44ad-8082-841d2941d90b, Duration=169ms)Unable to load DLL 'libgmp-10.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
I tried to see the \wwwroot files on the azure functions console but then i get this error:
3 [main] ls (8392) C:\Program Files\Git\usr\bin\ls.exe: *** fatal error - Couldn't set directory to \\?\PIPE\ temporarily.
Any hints?
It seems that the deployment is not done correctly.
Libgmp-10.dll a DLL (Dynamic Link Library) file which is referred to
essential system files of the Windows OS. It usually contains a set of
procedures and driver functions, which may be applied by Windows.
Please delete the Azure Function and, re-create and deploy a fresh code using Develop and publish .NET 5 functions using Azure Functions OR if you are using ADO, Setting up a CI/CD pipeline for Azure Functions.
Let me know if you have any follow up questions.
I built a c# Azure functions app triggerred by an Http Request. The purpose of this app is to use digital twin to change the desired status of my device. In order to do that, I have imported the following dependencies (within the project.son file):
"Microsoft.Azure.Devices": "1.17.2",
"Microsoft.Azure.Devices.Client": "1.19.0",
"Microsoft.Azure.Devices.Shared": "1.15.2",
"Newtonsoft.Json": "12.0.1"
Here is my error, when I want to return a HttpResponseMessage
req.CreateResponse<string>(HttpStatusCode.BadRequest, "Please pass a status on the query string or in the request body");
I get the following error :
[run.csx] 'HttpRequestMessage' does not contain a definition for 'CreateResponse' and the best extension method overload 'HttpRequestMessageExtensions.CreateResponse<string>(HttpRequestMessage, HttpStatusCode, string)' requires a receiver of type 'HttpRequestMessage'
I suspect dependencies to cause this error but I haven't found any solution on internet.
Do you have an idea how to solve this ?
Thanks
Solution:
Go to kudu(https://<functionapp>.scm.azurewebsites.net/DebugConsole) and navigate to D:\home\data\Functions\packages\nuget, delete system.net.http package then restart the function app.
Explanation:
HttpRequestMessage locates at assembly System.Net.Http.dll. I found that Function host references the assembly from GAC(Global Assembly Cache). On Azure, file path is D:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll. The reference cannot be redirected to the one we install using nuget(packages you installed reference System.Net.Http.dll internally), or we'll get error.
I'm trying to run firebase functions locally but I get the error:
Exception while executing function: Functions.TestMe. Microsoft.Azure.WebJobs.Host: One or more errors occurred. Exception binding parameter 'req'. mscorlib: Cannot create an abstract class.
I have an azure cloud function project in VSCode with just this function:
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;
using MongoDB.Bson;
using MongoDB.Driver;
namespace Learning.Platform
{
public static class TestMe
{
[FunctionName("TestMe")]
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequest req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
var db = new MongoClient(/*snipped*/);
var hey = db.GetDatabase("dude").GetCollection<object>("hey");
return (ActionResult)new OkObjectResult($"Hello, {hey}");
}
}
}
I would have thought this would just work because it's a fairly basic example of azure functions.
I'm using the Azure .net SDK version 2.9, Azure Tools 1.3.0 and the .Net Core 2.0 framework.
I gave up out of frustration and uninstalled the .net core framework and azure tools then reinstalled both.
Issue resolved itself.
For anyone who runs into this. I had the same issue, and was able to resolve it. I ran into this while trying to mess around and create an F# HttpTrigger function against v2 of the azure function runtime (since they don't have templates for that yet...).
Anyway, my issue was that I had installed the System.AspNetCore.Http Nuget package into my project while I was troubleshooting something else. After removing the reference to the Nuget package (Leaving only the Microsoft.NET.Sdk.Functions) it started working again.
There was an an issue within the azure storage assembly - i run in the same problem as i tried run a webjob - but the azure storage team fixed it