Altova MapForce 2024 Professional Edition

Example: Import Custom .NET DLL Assembly

Home Prev Top Next

This example shows how to import a custom .NET DLL assembly created in C# into MapForce. The source code of this sample is available at the following path: <Documents>\Altova\MapForce2024\MapForceExamples\C#\Format. The .dll assembly file that will be imported into MapForce is in the ..\bin\Debug directory. You can also open the .sln solution  file in Visual Studio and compile a new .dll file.

 

Note:If you want to use custom .NET functions in the built-in output preview (in the Output pane), these functions need to be compiled for .NET Framework 4.x or .NET Standard 2.0.

 

.NET assembly import

To import a .NET assembly file, take the following steps:

 

1.Click the Add/Remove Libraries button at the bottom of the Libraries window. The Manage Libraries window opens (see screenshot below).

mf_manage_libraries_window_empty

2.To import functions as a local library (in the scope of the current document only), click Add under the current mapping name. To import functions as a global library (at program level), click Add next to Global Library Imports. When you import a library locally, you can set the path of the library file to be relative to the mapping file. With globally imported libraries, the path of the imported library is always absolute.

 

3.Search for Format.dll in the following directory: ...\MapForceExamples\C#\Format\bin\Debug\. A message appears informing you that a new library has been added. The imported library is now visible in the Libraries window.

mf_import_cs_lib

If you do not see the newly imported library in the Libraries window, make sure that the transformation language is set to C#. To add the function to the mapping, drag it from the Libraries window into the mapping area. For more information, see Add a Function to the Mapping.

 

Mapping output

To preview the mapping output, take the following steps:

 

1.Open the FormatNumber.mfd file available in the following folder: ...\MapForceExamples\C#. This is a sample mapping that has an imported .dll library mentioned above.

2.Click the Output button to see the result of the mapping (see screenshot below).

csh-lib3

 

Mapping in C#

To run the mapping from a custom C# application, follow the instructions below:

 

1.Click Generate Code In | C# in the File menu.

2.Select a target directory where the code should be generated and click OK.

3.Build the application with Visual Studio and run the generated console application. For more details, see Generating C# code.

 

© 2017-2023 Altova GmbH