Using Firestore with Azure Functions V2 (C#) - c#

I am trying to use Firestore with Azure Functions, but I'm getting the following error:
System.Private.CoreLib: Exception while executing function:
HelloWorld. Grpc.Auth: Could not load type 'Grpc.Core.CallCredentials'
from assembly 'Grpc.Core.Api, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=d754f35622e28bad'.
I tried to use the steps from this question:
Grpc.Auth: Could not load type 'Grpc.Core.CallCredentials' from assembly 'Grpc.Core.Api'
however, it's related to the Language APIs, and the solution doesn't work for Firestore.
I tried changing the version of Grpc.Auth to 1.19.0, but this version doesn't appear to be supported by Firestore 1.0.0.
If I remove Firestore from the project and use grps.Auth 1.19.0 to initialize the Credentials object - this works. But the object isn't compatible with Firestore.
I also tried the PostBuild/PostPublish commands described in that question, but the commands fail to execute.
Before trying to use Firestore with Azure Functions, I successfully managed to use it with a .NET Core Web API project, but I'm struggling with Azure Functions and would appreciate any help.

It seems that it is a bug in Azure Functions and you could refer to this issue to track it.
If you update the cli directory to contain the relevant files from Grpc.Core and Grpc.Core.Api, and update func.deps.json accordingly, it all works - including Google.Cloud.Firestore.
So basically, this is a problem for any function needing to use a version of Grpc.Core later than the one embedded in the CLI application.

Related

Cannot add existing .NET Core 3.1 Project to Azure Function Project

When I add an existing .NET Core 3.1 project to my Azure Function I get
'Microsoft.Extensions.Primitives, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
The system cannot find the file specified."
When I try to execute a standard Http Trigger which works fine when the project is not referenced
This is a really frustrating issue that I have no idea how to resolve
How can I fix this or at least get information about what is causing it?
There is clearly some kind of compatibility issue but I have no idea where to start as the project reference I am trying to add has a lot of code in it
Are there any specific actions I need to take when preparing the function project like copying files, etc?
As soon as I reference my Class library, either directly or indirectly, I get this issue
I raised this question earlier
Adding Reference to Class LIbrary in Azure Function project causes assembly not found
I have raised this as a separate one as I think there may be specific actions I have to perform when referencing projects like this which may not be specific to my exact assembly
Cheers
Paul

Azure Function: System.Private.CoreLib: Could not load file or assembly 'System.ComponentModel.Annotations...'

I have .NET Standard 2.1 class library, which includes an object-model with properties attributed with DataAnnotations. I'm consuming it from a v3 Azure Function targeting .NET Core 3.1. I'm able to use the library no problem from a .NET Core console app, but when I consume it from the Azure Function app I get this error at runtime:
System.Private.CoreLib: Exception while executing function: ... System.Private.CoreLib: Could not load file or assembly 'System.ComponentModel.Annotations, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
Interestingly, I don't get this error when populating the object-model, only when trying to serialize it to JSON.
I've tried adding the System.ComponentModel.Annotations nuget package to the functions project as well, and tried suggested fixes for similar issues such as https://stackoverflow.com/a/44079161/892770 and https://stackoverflow.com/a/50776946/892770 to no avail.
Any ideas? Thanks!
I take it back, this answer, Azure Function, EF Core, Can't load ComponentModel.Annotations 4.2.0.0, did indeed fix my issue. I was hitting an exception on Assembly.Load in the CurrentDomain_AssemblyResolve function and thought I was still failing, but it looks like that's expected.

Unable to load assembly or dll System.Buffers, Version=4.0.2.0 in Azure function

I have one Web API application,Added System.buffer reference 4.0.3.0.
When we call this project from another project from the same solution it's working fine.
But when I refer to this project reference in Azure function - It's throwing following error.
I have tried to make changes by changing versions but no luck.
In Azure function, we are just referencing project.
<TargetFramework>net462</TargetFramework>
The Azure Functions 1.x Runtime does not support binding redirects (github issue).
I ended up writing code to apply the binding redirects myself, based on this answer.

Azure functions runtime binding failing for System.IO.Packaging using OpenXML SDK

I have a project which ran fine as an Azure Function in v1 of the Functions runtime, but I'm busy rewriting it for v2 and I'm stuck.
My Azure Function relies on a library of mine, which in turn depends on another library. Both libraries depend on the Open XML SDK, which I've installed in those projects via NuGet. They both also have System.IO.Packaging installed via NuGet.
If I run my code through a console app, it runs fine. When I try to run it as an Azure Function, it gets partway through my library code but then the functions runtime falls over with the error:
System.Private.CoreLib: Exception while executing function: getWorkbook. ExcelGenerator: Could not load file or assembly
'System.IO.Packaging, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file
specified.
I've tried adding System.IO.Packaging to the Azure Function project (which I realise I ought not to need to do) but it then falls over with a new error:
System.Private.CoreLib: Exception while executing function:
getWorkbook. ExcelGenerator: Could not load type
'System.IO.Packaging.CompressionOption' from assembly 'WindowsBase,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
I'm suspicious about the 0.0.0.0 version number in the first error, and I really don't understand the second one (or honestly why adding System.IO.Packaging to the Azure Function makes any difference at all, given that this is just running compiled library code).
One other curious thing is that WindowsBase does not show up in the "Assemblies" dependency list for my Azure Function, but it does show up checked in the "add reference" dialog box. If I uncheck it, I get a mysterious error saying "No assembly reference with the name "{0}" could be found in the project".
I'm pretty sure somehow System.IO.Packaging or WindowsBase just isn't making it through to the Azure deployment, but I'm not sure how. I'm rapidly discovering that I don't know very much about how DLL dependencies work at all let alone in Azure - any ideas?
To rewrite v1 function to v2, right click on Function project, and Edit FunctionProjectName.csproj, change TargetFramework of Function project to netcoreapp2.1, AzureFunctionsVersion to v2.
And we may have to install packages for v2 function as they are not built-in any more as in v1.
Code refactoring is necessary, if we meet any assembly problem then, try the code in .Net Core console app to see whether it's a .net core problem or related to Function runtime.
If there're some configurations in host.json, need pay attention as some of their format has been changed.
Usually, creating a template v2 function and compare old content with new v2 template is recommended.

Azure Function stopped working - Could not load type 'Microsoft.Azure.WebJobs.BlobTriggerAttribute'

My always running function stopped working recently. So I started to look what's changed, loaded solution locally in VS2017 and hit compile. Everything seems to be compiling but when I run it locally I get:
Error indexing method 'CheckNewBlob.Run'
Microsoft.Azure.WebJobs.Host: Error indexing method 'CheckNewBlob.Run'. System.Private.CoreLib: Could not load type 'Microsoft.Azure.WebJobs.BlobTriggerAttribute' from assembly 'Microsoft.Azure.WebJobs, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null'
ok, I tried to register the binding and tried to install latest Azure.WebJobs.Core (whatever it's called) package - no luck! It just does NOT compile anymore! I even tried to recreate the project and that was waste of time. Not the function is broken.
And haven't even gotten to Table storage output...
So, Azure functions team, what should we do with all that?
Suffice to say the existing function is not triggered anymore by new blobs. It used to work just yesterday, but that's it, not anymore.
Azure Functions Core Tools (2.0.1-beta.36)
Function Runtime Version: 2.0.12050.0
https://github.com/Azure/app-service-announcements/issues/129 has everything you need to know (and email was sent earlier about it to all subscription owners). See also https://github.com/Azure/azure-functions-host/issues/3363.
Quoting for your particular error:
You'll get this if you're using Azure Storage based functionality (blob/queue/tables trigger/input/output) and you haven't installed the Microsoft.Azure.WebJobs.Extensions.Storage extension.
Changing Platform from 32 Bit to 64 Bit fixed this issue for me.

Categories

Resources