Inkey Solution Logo
banner

Blogs

Add an external assembly as a reference in the Azure function

, December 3, 2018 8012 Views

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

mm

Inkey

INKEY is your solution partner.
Our focus is to deliver you in-time intelligent innovative solutions ("key") for the problems in hand. Maintaining a quality standard right from the inception of a project is our top most priority.

Our team of talented professionals will execute your projects with dedication and excellence. We take ownership and accountability for the effort that goes into meeting our client’s needs.

Years of experience and proven success of delivering innovative custom solutions.

More posts by

3 responses to “Add an external assembly as a reference in the Azure function”

  1. Gerhard says:

    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

    • Admin says:

      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.

Leave a Reply

Your email address will not be published. Required fields are marked *

The maximum upload file size: 2 MB. You can upload: image, audio, video, document, spreadsheet, interactive, text, archive, code, other. Drop file here

Would you like to digitize your business and put it on the cloud?
Do you need clear, concise reports for your organization?