I’ve written in the past how to use .NET assemblies in AL for your on-premise extensions and all is also officially documented here, but I think there are some tricky aspects that must be more explicited:
- In order to use your .NET assemblies (DLLs), in Visual Studio Code you need to set the assemblyProbingPaths option to point to the folders containing the assemblies that you will use.
- Visual Studio Code doeas not read the GAC by default. You have to insert the path in the al.assemblyProbingPaths option as above.
- You should always specify the Version of the assembly (at least the major version), otherwise, the compiler will pick whatever it thinks is the best match, which, depending on many factors (and sometimes this is not what you want to have).
- When you compile your project in Visual Studio Code, the compiler verifies that it can locate all the .NET assemblies you’ve referenced. When this process is successfully completed, it creates an app file containing your AL files. This app file is sent to the server where the AL files are recompiled in the server’s context. If the server’s context is missing some references, the compilation will fail and you will not be able to publish your extension (normally the error is something like
error AL0451: An assembly named 'XXX' could not be found
- Remember that there is no connection between Visual Studio Code and its settings and your D365BC service instance. The server caches assembly lookups, so if you move assemblies and if you do not restart the server after moving that assemblies around or creating symbolic links, the new assemblies are not picked up (and you could have a compilation error at server side).
- The official Microsoft’s documentation says that when publishing your extension “The server will search the global assembly cache (GAC), the Add-Ins folder, and the Add-in table. You must manually install any custom assembly in one of these locations.“. It seems instead that in the current release of Business Central, the server only searches the Add-Ins folder, the Add-in table and the TempAddIns folder for assemblies. In the next release it will probe the GAC and the server’s bin folder.