Let’s learn today, how to add an external assembly as a reference in an azure function with a small example. This will help you to reuse the already developed functionalities (i.e.,) if there is a requirement that some of the functionalities are needed inside the azure function, which are already developed in any of the class library project then, this is possible by using a feature provided by the azure portal.
Let us consider that a class file in an assembly has the below lines of code in it.
namespace Automobiles { public class Cost { public static int GetCost() { return 5000; } } }
Now, if we want to use the above GetCost() method in our azure function then, we have to provide the reference of the above file in the azure function.
For that, open the “Function App” folder of the azure portal, where we can see the “App Service Editor” screen. Now, click on the “WWWROOT” folder, and then, under the required azure function, create a “bin” folder and add the Automobiles.dll library in it. This would look somewhat similar as the below screen shot:
After completing the above steps, include the below lines on the top of the azure function which specifies that the specified dll is being referenced as an external library:
#r "Automobiles.dll" using Automobiles;
Now, we can access the methods of the class in the above library using the absolute path as follows:
int cost = Cost.GetCost();
Below is a sample code using the above method:
I hope this helps you.
Insert data into Many-to-Many relationship in Dynamics CRM very easily & quickly, using the Drag and drop listbox.
http://www.inkeysolutions.com/what-we-do/dynamicscrmaddons/drag-and-drop-listbox
Create a personal / system view in Dynamics CRM with all the fields on the form/s which you select for a particular entity using the View Creator.
http://www.inkeysolutions.com/what-we-do/dynamicscrmaddons/view-creator
© All Rights Reserved. Inkey IT Solutions Pvt. Ltd. 2024
Hi,
Could you please elaborate on the following please:
1. Is the execution of GetCost() regarded as being part of the Azure Function that called it? Is its execution time added to the time of the Azure Function and is its cost therefore added to the cost of the Azure Function?
2. What happens if GetCost() needs to execute longer than what the function can run (longer than 10 minutes on assumption plan)?
Regards
Gerhard
Gerhard,
1) Since we are referencing the external DLL for example in this case “Automobiles.dll” it will be considered as the part of Azure function execution and the time taken to execute a function inside the external DLL will also be added to the execution of Azure function.
Also, yes the cost will be added along with the Azure function.
2) If GetCost() method takes more than 10 minutes of execution time then there will be an execution time-out issue.
In short, the behavior of the Azure function will be the same. The only purpose of using the external DLL file is to make reuse of the existing code which has already been implemented.
Hope I have answered your questions.
Many thanx for your answers. Clear and helpful.
Regards
Gerhard