question

NandanHegde-7720 avatar image
0 Votes"
NandanHegde-7720 asked krish-gh commented

How to add reference to directives in Azure function via Portal

Hello All,

I have created a function via Portal

28209-af.png




When I execute the code, i am getting the below error:
The namespace Newtonsoft not exits.

Similarly getting the error for all the above directives.


So wanted to know how do we add reference of the directives to the function via Azure Portal?

azure-functions
af.png (29.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

krish-gh avatar image
0 Votes"
krish-gh answered krish-gh commented

Since you are using C# script (.csx), and not the regular C# here, to load external assembly like "Newtonsoft.Json", "Microsoft.WindowsAzure.Storage", add below on top of your script.

 #r "Newtonsoft.Json"
 #r "Microsoft.WindowsAzure.Storage"

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

For any other outside the above list, consider adding nuget reference as mentioned in Using NuGet packages.

For anything which does not have nuget packages. follow Referencing custom assemblies.

NOTE: There are specific ways of loading assembly on .csx script in Azure Function. Luckily, in this case, 'Newtonsoft.Json' is available out of the box. Refer this for details. Also, you won't be able to upload dll from portal if WEBSITE_RUN_FROM_PACKAGE=1, you need to go via publish route.



· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello KrishnenduGhosh,
Thank you for the help :)

I had tried the below scenarios :
https://poszytek.eu/en/microsoft-en/azure-en/references-in-azure-functions-custom-dlls-how-to/

But I am not able to manually upload the dll via Portal:

28336-kudu.png


But when I publish my code via VS in another Azure function, I am able to see all Dlls in bin file:

28401-deployment.png




So wanted to know how to upload the DLLs via Portal?

0 Votes 0 ·
kudu.png (9.0 KiB)
deployment.png (45.4 KiB)

Hello @NandanHegde-7720 , sorry I am trying to understand, do you mean the link I shared in my answer did not help to solve the actual problem you posted in the question or it's something else? For the other problem of uploading dlls, I would suggest you to post a separate question. If the problem of 'Newtonsoft.Json' error got solved by this answer, kindly consider marking it 'Accepted' please.



0 Votes 0 ·

Hello KrishnenduGhosh,
I had checked that link, but no where it mentions as to how to upload the custom Dlls via portal in Bin folder for reference.
So can you please guide me as to how to upload the DocumentFormat.openxml.dll in bin folder via Portal?

As I had mentioned that along with:
The namespace Newtonsoft not exits.

Similarly getting the error for all the above directives.

0 Votes 0 ·
Show more comments