Loading assemblies

A .NET assembly is a package of types, metadata, and executable code. In .NET applications, all code must be in an assembly. Assembly files have the extension .dll or .exe.

There are the following types of assemblies:

  • Private assemblies   A private assembly is a file in the file system.

  • Shared assemblies   A shared assembly is an assembly that is installed in the global assembly cache.

Before MobiLink can load a class and call a method of that class, it must locate the assembly that contains the class. MobiLink only needs to locate the assembly that it calls directly. The assembly can then call any other assemblies it needs.

For example, MobiLink calls MyAssembly, and MyAssembly calls UtilityAssembly and NetworkingUtilsAssembly. In this situation, MobiLink only needs to be configured to find MyAssembly.

MobiLink provides the following ways to load assemblies:

  • Use -sl dnet ( -MLAutoLoadPath )   This option only works with private assemblies. It sets the path to the application base directory and loads all the assemblies within it.

    When you use the -MLAutoLoadPath option you cannot specify a domain when entering the fully qualified method name for the event script.

    When you specify a path and directory with -MLAutoLoadPath, MobiLink does the following:

    • sets this path as the application base path

    • loads all classes in all files ending with .dll or .exe in the directory that you specified

    • creates one application domain and loads into that domain all user classes that do not have a domain specified

    Assemblies in the global assembly cache cannot be called directly with this option. To call these shared assemblies, use -MLDomConfigFile.

  • Use -sl dnet ( -MLDomConfigFile )   This option works with both private and shared assemblies. It requires a configuration file that contains domain and assembly settings. You should use this option when you have shared assemblies, when you don't want to load all the assemblies in the application base path, or when for some other reason you need to use a configuration file.

    With this option, MobiLink reads the settings in the specified domain configuration file. A domain configuration file contains configuration settings for one or more .NET domains. If there is more than one domain represented in the file, the first one that is specified is used as the default domain. (The default domain is used when scripts do not have a domain specified.)

    When loading assemblies, MobiLink tries to load the assembly first as private, and then attempts to load the assembly from the global assembly cache. Private assemblies must be located in the application base directory. Shared assemblies are loaded from the global assembly cache.

With the -MLDomConfigFile option, only assemblies that are specified in the domain configuration file can be called directly from event scripts.

Sample domain configuration file

A sample domain configuration file called mlDomConfig.xml is installed with MobiLink. You can write your own file from scratch, or edit the sample to suit your needs. The sample file is located in the SQL Anywhere path, in

MobiLink\setup\dnet\mlDomConfig.xml

The following is the content of the sample domain configuration file mlDomConfig.xml:

<?xml version="1.0" encoding="utf-8"?>
<config xmlns="iAnywhere.MobiLink.mlDomConfig" xsi:schemaLocation='iAnywhere.MobiLink.mlDomConfig mlDomConfig.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >
    <domain>
        <name>SampleDomain1</name>
        <appBase>C:\scriptsDir</appBase>
        <configFile></configFile>
        <assembly name="Assembly1" />
        <assembly name="Assembly2" />
    </domain>

    <domain>
        <name>SampleDomain2</name>
        <appBase>\Dom2assembly</appBase>
        <configFile>\Dom2assembly\AssemblyRedirects.config</configFile>
        <assembly name="Assembly3" />
        <assembly name="Assembly4" />
    </domain>
</config>

The following is an explanation of the contents of mlDomConfig.xml:

  • name   is the domain name, used when specifying the domain in an event script. An event script with the format "DomainName:Namespace.Class.Method" would require that the DomainName domain be in the domain configuration file.

    You must specify at least one domain name.

  • appBase   is the directory that the domain should use as its application base directory. All private assemblies are loaded by the .NET CLR based on this directory. You must specify appBase.

  • configFile   is the .NET application configuration file that should be used for the domain. This can be left blank. It is usually used to modify the default assembly binding and loading behavior. Refer to your .NET documentation for more information about application configuration files.

  • assembly   is the name of an assembly that MobiLink should load and search when resolving type references in event scripts. You must specify at least one assembly. If an assembly is used in more than one domain, it must be specified as an assembly in each domain. If the assembly is private, it must be in the application base directory for the domain.

For more information about the mlsrv11 option -sl dnet, see -sl dnet option.