I have tried the below in a version 4 Azure Function app
#r "Polly"
using System;
using System.Threading.Tasks;
and/or
using System;
using System.Threading.Tasks;
using Polly;
But in both cases it says Polly is not found. From the docs I tried to add a framework 46 reference too in the json file for the function app but that did not work. What is the best way to import a dependency?
One of the workaround to install Polly dependency injection in Azure Functions v4 is:
Open the Azure Functions V4 Project.
Right-click on the project > Click on Manage Nuget Packages
Install the required extensions for your project like
Start writing the code related to Polly policies extension in the function class like:
The ways to add the dependency injections in the Azure Functions is:
Installing the Dependency Injections using NuGet Package Manager by right clicking on the project.
Or
Using the DotNet CLI or Package Manager commands available in the NuGet official Site.
Related
I created a Timer Azure Function that called an API and wrote that json response to Azure SQL DB.
I wanted to continue my project, so I created an Azure Functions App in VS2017. I moved my code over and changed the #r script reference to the precompiled reference for the sqlclient.
From: (script calls)
r System.Configuration
r System.Data"
TO: (pre-compiled calls)
using System.Configuration;
using System.Data.SqlClient;
using System.Threading.Tasks;
Now I'm receiving a missing assembly reference for "System.Data.SqlClient" and I'm not sure how to add it to my Azure Functions App project in VS.
Please go to your csproj to check which framework you are targeting. Based on your error, I guess it looks like this:
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
Which means you are on .NET Standard / Functions V2.
Either change it to .NET Framework / Functions V1:
<TargetFramework>net461</TargetFramework>
or reference the .NET Standard version of System.Data.SqlClient:
<PackageReference Include="System.Data.SqlClient" Version="4.4.3" />
V1 is the production version for now, and it's the one used for C# script, so I suggest you stick to it.
So I have some Azure Functions I need to publish, which I want to do via a functions project. However, those functions rely on references to class libraries within my solution, and the references do not work within a functions project, is there a way around this?
Edit: After adding the references to the other projects, when "using" the namespaces in which the classes are kept, the compiler throws an error "cannot resolve symbol", it is as if the reference does not exist. The functions project will not build because it cannot find the namespace in which the classes exist
Verify that each project targets the same version of .NET framework. I had the same problem until I noticed that the referenced project targeted 4.7.1, but my Azure function project targeted 4.6.1. Changing the referenced project to match the Azure function project resolved the issue.
There are a couple more steps to consume assemblies if they're not exposed by default in Azure Functions. If it's a custom assembly you have to make sure it's included in the bin folder. Then you have to make sure you're using the #r directive. Are you doing both of those things? Include your code header and settings if so.
This page has the list of assemblies that are visible to Azure Functions, some still requiring the #r directive:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#referencing-external-assemblies
The following assemblies are automatically added by the Azure Functions hosting environment:
mscorlib
System
System.Core
System.Xml
System.Net.Http
Microsoft.Azure.WebJobs
Microsoft.Azure.WebJobs.Host
Microsoft.Azure.WebJobs.Extensions
System.Web.Http
System.Net.Http.Formatting
The following assemblies may be referenced by simple-name (for
example, #r "AssemblyName"): Newtonsoft.Json
Microsoft.WindowsAzure.Storage Microsoft.ServiceBus
Microsoft.AspNet.WebHooks.Receivers Microsoft.AspNet.WebHooks.Common
Microsoft.Azure.NotificationHubs
How do I upload a pre-compiled .NET assembly(-ies) and execute my code as Azure Functions?
I'm looking for a way to run some complex domain logic, which is contained inside custom assemblies and is covered by unit tests etc.
What kind of limitations for this code are there? E.g. access remote data stores, networking etc.
Update: The below answer is still correct (still works), however there is now also first class support for precompiled functions. See the wiki page for more information on that.
The documentation (link here) describes how you can reference external libraries and Nuget packages from a C# Function using the #r syntax, e.g:
#r "System.Web.Http"
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
public static Task<HttpResponseMessage> Run(HttpRequestMessage req)
Additional details on this can be seen in this SO post.
You can also deploy custom executables and call them from your Azure Functions. For example, if you start from the Windows BAT template, you can use that to call out to an exe. Here's a sample of this in our repo, showing an image resize example. In this sample, we have a BAT script that is triggered whenever a new image is uploaded to a blob container, and the script calls out to a Resizer.exe tool to do the resize:
.\Resizer\Resizer.exe %original% %resized% 200
Regarding limitations, all Azure Functions code runs in the App Service sandbox whose limitations are described here.
To run a pre-compiled .NET assembly in an Azure Function, it's possible to upload a custom dll by FTP in the function root folder (within a bin folder) and then use #r to reference it from the azure function code.
Here is an example, a dll named "WorkOnImages.dll" is uploaded in an azure in azure function folder :
Then the dll is referenced in the azure function :
Here is the source blog post
Discouraged by the lack of Azure Function tooling support for VS2017, incompatibility with Azure SDK 3.0, I was about to throw in the towel for Functions and fallback to an approach using VS2017 and WebJobs SDK.
Then announced on March 16th, 2017, the easiest approach is documented here in an excellent blog post by Microsoft's Donna Malayeri.
It does everything I could want - true intellisense, debugging capabilities. It's been great and I wouldn't look back.
I'm using VS 2015 for developing NodeJS console applications.
I have just created a new project from ExpressApp template.
I wanted to use 'azure-storage' packages in code.
I installed using the npm wizard VS 2015 offers and I can see the package installed in the Solution explorer under 'npm'.
Yet, I cannot require:
import azure = require('azure-storage');
Saying:
cannot find module 'azure-storage'
cannot find external module file by specified path.
You can see this in the attached picture.
Here's what I did following these two posts:
post 1 post 2
What can I do else?
thanks
It should be
var azure = require('azure-storage');
Currently, there is not an official azure sdk for typescript present. And import in typescript just can import typescript modules.
you can try to leverage the TypeScript type definitions to allow require function in typescript.
This solution leverages this answer of Importing node-modules with TypeScript on SO. Code sample should like:
///<reference path='node.d.ts'/>
var azure = require('azure-storage');
Be the way, this group has transferred azure sdk for node to typescript https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/node-azure which you can try to use directly in typescript. But the version of this sdk is a little out of date.
In new version you can defined like this.
import * as azure from 'azure-storage';
I'm trying to commission an HDI cluster using the .Net SDK. The tutorial is pretty self explanatory, but when I follow along, I seem to be missing a reference.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Hyak.Common;
using Microsoft.Azure;
using Microsoft.Azure.Common.Authentication;
using Microsoft.Azure.Common.Authentication.Models;
using Microsoft.Azure.Management.HDInsight;
using Microsoft.Azure.Management.HDInsight.Job;
using Microsoft.Azure.Management.HDInsight.Job.Models;
using Microsoft.Azure.Management.HDInsight.Models;
using Newtonsoft.Json;
namespace CreateHDICluster
{
internal class Program
{
private static ProfileClient _profileClient;
....
}
}
results in a 'The type or namespace name 'ProfileClient' could not be found (are you missing a using directive or an assembly reference?)'
Best guess, whatever version of whatever package the ProfileClient class belongs to no longer contains this class - the tutorial doesn't specify a version and a few of them packages are pre-release.
Does anybody have this working? To what does the ProfileClient class belong?
Thanks
This appears to be a bug, as you have the correct references in your project. Note the open sourced GitHub repo and the class definition for ProfileClient:
https://github.com/Azure/azure-sdk-for-net/blob/21db6e5490e66af39a9c6dbf0ad10650d9ca037b/src/Authentication/Common.Authentication/Common/ProfileClient.cs
This file exists within the namespace: Microsoft.Azure.Common.Authentication
I suggest filing an issue with the repo. Also note that the packages requested to bring in, particularly Microsoft.Azure.Common.Authentication is in prerelease
I believe this issue you found in the article's sample was due to the removal of ProfileClient from the Authentication package -- the article's sample is now updated.
If you're still interested, you could take a look at the updated sample in the article.
I hope this helps!