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.

  1. 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"

Visual Studio Code - Dynamics 365 Business Central (Navision) Einrichtung für OnPrem .NET Interoperabilität

  1. 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;

VS Code Dynamics 365 Business Central (Navision) - AL: Download symbols

  • search for Configure Language Specific Settings...

Visual Studio Code - Configure Language Specific Settings für .NET

  • Select AL language. The user setup file settings.json is opened for editing;

Visual Studio Code und Dynamics 365 Business Central (Navision)

  • Then search for the command al.assemblyProbingsPahts and execute it;

Visual Studio Code Pfade für .NET Interoperability in Dynamics 365 Business Central (Navision)

  • Enter all paths. In our example, they look like this:

Visual Studio Code Beispiel des Pfades für .NET Interoperability

  1. Now we can write a codeunit where the .NET methods are used.
    1. We have added a method from mscorlib: System.DateTime;
    2. We've added a method other than mscorlib: System.Net.Http.HttpResponseMessage. This is used in another example about OData;
    3. We have added an EventSubscriber to the 'Company Information' Page - OnOpenPageEvent;
    4. The Subscriber method calls the DateTime method;
    5. Both .NET assemblies have been compiled.

Dynamics 365 Business Central (Navision) - .NET Klasse DateTime Beispiel

  1. The result is displayed when opening the company data page.

Dynamics 365 Business Central (Navision) - Infofenster - Datum von .NET DateTime

  1. 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 (Navision) - .NET Pfade werden auskommentiert

Dynamics 365 Business Central TM (Navision) Developer and Consultant View Konrad Buczkowski's LinkedIn profile Monika Wichrowska