04.07.2017

Microsoft .NET Framework Interoperability In Dynamics NAV

How to start using .NET Framework to extend Microsoft Dynamics NAV features? Read more on our blog.

.NET Framework is a development platform, developed by the Microsoft company. This platform includes creating new applications for the Microsoft operating systems. .NET provides us class libraries and runtime environment (CLR), which give us tools and functions for applications. Programming languages that we can use on this platform include: C#, J#, C++, VB.NET.

The most popular language in every day work is C#. It’s based on the C language, constantly supported and developed with additional functions.
.NET Framework has its own structure, which we can divide as follows:

  1. Class libraries (e.g. ASP.NET, Web Services, Web Forms, XML, ADO.NET etc.)
  2. Own runtime environment (CLR)
  3. Visual Studio .NET
In Microsoft Dynamics NAV we can use .NET Framework to extend our system with new features.
There are two possibilities for implementing .NET libraries in Dynamics NAV.
  1. We can use ready-made DotNet library (we have to create new variable with DotNet data type and select library from the list.
  2. We can create new .NET library.

This example can illustrate, how to implement own .NET scripts in Dynamics NAV.

Step 1. Run Microsoft Visual Studio (e.g. free version of this program Visual Studio 2017 Community) and create new project. Click on the File tab and then NewProject.
Step 2. On the list, find Class Library (.NET Framework) and set project name in Name field.

Step 3. Write script code (in C#) which will be implemented in NAV.
Step 4. When you have prepared your code, you have to build your project. Click on Build tab and then Build Solution. You can also use a shortcut key (Ctrl + Shift + B) to do this.
Step 5. After build, you have to find your .NET Framework library on .dll file. Right-click on the project name in Solution Explorer and select Open Folder in File Explorer. Then go to bin/debug catalog, where you can find your .NET library. Copy this file.
Step 6. Go to Dynamics NAV catalog (look at this screenshot) and paste your file.
Step 7. Run Microsoft Dynamics NAV and create a new Codeunit, where you will use your library. Then you have to declare a new variable with DotNet DataType.
Step 8. In Subtype field, press F6 and go to the Assembly by clicking an arrow icon. Find your file in a Server tab.
Step 9. After creating a new variable, you can declare new code using .NET script from your DotNet library. Your code can look like the one on this screenshot.
Step 10. Run this codeunit, and see the effects of our work.

Done! You implemented your own .NET class library in Dynamics NAV.