Business Central, AL, Visual Studio Code and .NET Interoperability
In this article, we'll show what settings and steps should be made to use .net interoperability in Dynamics 365 Business Central (formerly Navision). .NET interoperability is only available in on-premise version. Cloud versions stay outside of this article.
-
In the first step, the app.json file needs to be extended with a parameter that shows it's an on-premise installation. "target": "OnPrem"
-
In the next step, we need to tell the compiler where to store all DLL libraries. By default, the compiler only knows where to look for the mscorlib assembly. The path can be defined with a command "al.assemblyProbingPaths". The setup is saved in the user settings in the settings.json file. Detailed steps:
-
Open Command Pallete with Ctrl + Shift + P;
-
search for Configure Language Specific Settings...
-
Select AL language. The user setup file settings.json is opened for editing;
-
Then search for the command al.assemblyProbingsPahts and execute it;
-
Enter all paths. In our example, they look like this:
-
Now we can write a codeunit where the .NET methods are used.
-
We have added a method from mscorlib: System.DateTime;
-
We've added a method other than mscorlib: System.Net.Http.HttpResponseMessage. This is used in another example about OData;
-
We have added an EventSubscriber to the 'Company Information' Page - OnOpenPageEvent;
-
The Subscriber method calls the DateTime method;
-
Both .NET assemblies have been compiled.
-
The result is displayed when opening the company data page.
-
Now for the test purpose, we temporarily delete all the paths that we defined in step I in settings.json. After the file is saved again, the compiler can not recognize a class other than mscorlib.
Dynamics 365 Business Central TM (Navision) Developer and Consultant Monika Wichrowska