# 16. Runtime Hosting

Chapter Contents | Prev | Next
Keyword Search:
www.openlinksw.com
docs.openlinksw.com
Book Home
Contents
Preface
Runtime Hosting
Runtime Environments
CLR, .Net & ASPX Host
CLR & Mono
Environment Setup Testing the Virtuoso Mono Runtime Environment
Embedded Java VM API
Virtuoso Server Extension Interface (VSEI) (C Interface)
VSEI Plugins

## 16.3. CLR & Mono

The Mono Project is an open development initiative sponsored by Ximian that is working to develop an open source, Unix version of the Microsoft .NET development and run time platform. Its objective is to enable Unix developers to build and deploy cross-platform .NET Applications. Likewise, this expands the capabilities of Windows programmers, this project opens .NET to non Windows platforms. Mono will implement various Microsoft technologies that have now been submitted to the ECMA for standardization.

The Goal is similar to that of Java, implementing a common virtual machine on multiple operating systems, however you are not restricted to one language.

Like .NET, Mono contains a Common Language Infrastructure (CLI) virtual, machine that contains a class loader, Just-in-time compiler, and a garbage collecting runtime; a class library that can work with any language which works on the CLR; a compiler for the C# language.

Windows has compilers that target the virtual machine from a number of languages: Managed C++, JavaScript, Eiffel, Component Pascal, APL, Cobol, Perl, Python, Ruby, Scheme, Smalltalk, Standard ML, Haskell, Mercury and Oberon. A single object system, threading system, class libraries, and garbage collection system can be shared across all these languages, the CLR.

The CLR and the Common Type System (CTS) enables applications and libraries to be written in a collection of different languages that target the CLR byte code. This means that you could define a class to do algebraic manipulation written in C#, that class can be reused from any other language that supports the CLI. You could create a class in C#, subclass it in C++ and instantiate it in an Eiffel program.

See Also:

The Create Assembly Syntax

The External Hosted Create PROCEDURE Syntax

### 16.3.1. Environment Setup

Ximian announced the launch of the Mono project, an effort to create an open source implementation of the .NET Development Framework.

Follow the steps below to configure the CLR runtime environment with Virtuoso:

1. Install Mono

   The Mono package is available from the Mono project home page in the form of an RPM for Linux. The source is also available.

2. Make mscorlib.dll available to /usr/local/lib

   The mscorlib.dll is installed by Mono and needs to be symlinked from its default location to /usr/local/lib.

### 16.3.2. Testing the Virtuoso Mono Runtime Environment

To test that you have successfully started the Virtuoso server with Mono CLR runtime support make a simple library, import the contained class into Virtuoso and call it.

Using an text editor create a C# source file in the server root directory called sanity.cs, with the following contents:

    using System;

    public class sanity
    {
        public static string test(string  name) {
           return "Hello "+ name + ", from Virtuoso";
        }
    }

This sample needs to be compiled into bytecode assembly before it can be used. Make sure you environment is configured to use Mono, change directory to the Virtuoso server root containing the C# source file. Run:

    bash$ mcs /target:library sanity.cs
    Compilation succeeded

Now this library must be introduce to the Virtuoso Server. Using ISQL use the following commands to test the CLR:

    C:\Program Files\OpenLink\Virtuoso 3.0\bin>isql 1112
    Connected to OpenLink Virtuoso
    Driver: 03.00.2315 OpenLink Virtuoso ODBC Driver
    OpenLink Interactive SQL (Virtuoso), version 0.9849b.
    Type HELP; for help and EXIT; to exit.
    SQL> DB..import_clr (vector ('sanity'), vector ('sanity'));

    Done. -- 300 msec.
    SQL> select sanity::test('Rob');
    callret
    VARCHAR
    ______________________________________________

    Hello Rob, from Virtuoso

    1 Rows. -- 60 msec.

Congratulations, you have proven that your Virtuoso server can run .NET classes via Mono Runtime.

See Also:

The Virtuoso Tutorials, which are installed with the Demo Virtuoso Server (port 1112), contains numerous samples further demonstrating the use of the CLR, .NET, Mono and Virtuoso.

See Also:

The Create Assembly Syntax

The External Hosted Create PROCEDURE Syntax

Previous CLR, .Net & ASPX Host | Chapter Contents | Next Embedded Java VM API