.Net Host Package

This package contains Java classes and interfaces for starting and hosting the Common Language Runtime which manages memory, thread execution, code execution, code safety verification, compilation, and other system services. It manages the .Net framework Engine and enables inter-process communication between Java applications and .Net libraries. This package has classes which automatically starts the .Net framework engine making it possible for an application written in Java to access the types in the Microsoft Common Object Runtime Library (mscorlib) or access all the types in an external library without prior registrations of the .net Library.


The following table represents the subpackages of the .Net Host Package:


The package contains classes for starting and hosting the .Net CLR. It also contains classes to load .net assemblies, view assembly types, methods, properties and fields, and dynamically create and invoke types.


The package contains classes for loading resources, logging exceptions and managing native library calls.


This package contains native pointers, types, function pointers, enums and methods to load native .Net libraries using JNA.


This packages contains native enums as set of named integer constants, an interface for enums that can be combined to a set based on an integer value or treated as a bit field (set of flags) as well as an enum utility for converting between integer flag and bit field enums.


This package contains utility classes for handling CLR Activaror, AppDomain, Array, Assembly, Event Delegate, Exception, Object as well as common CLR tasks.


This package contains an enumeration type for determining where a .Net Assembly should be loaded from.


This package contains numeric data types for handling inbuilt types missing in Java but available in .Net such as BigByte (byte in C#), UInteger (uint in C#), ULong (ulong in C#), UShort (ushort in C#) etc.

Source Code Example

How to use Activator to Create instance of a .Net Object

Exported from Notepad++
import com.dotNet4Java.*; import com.dotNet4Java.api.EClrError; public class CreateInstanceUsingActivator { static void displayObjectTypeInfo(Object AObject) throws EClrError { if (AObject == null) { System.out.println("Object has not been instantiated"); } else { IClrType m_type = TClrType.getObjectType(AObject); System.out.println("Object has been instantiated"); System.out.println("Assembly FullName: " + m_type.getAssembly().getFullName()); System.out.println("FullName: " + m_type.getFullName()); System.out.println("ToString: " + m_type.toString()); System.out.println(); System.out.println(); } } static void loadAssembly() throws EClrError { TClrAssembly.load("System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"); } static void createInstanceUsingTypeName() throws EClrError { IClrObject sqlConnection = TClrActivator.createInstance("System.Data.SqlClient.SqlConnection"); displayObjectTypeInfo(sqlConnection.toObject()); } static void createInstanceUsingType() throws EClrError { IClrType sqlConnectionType = TClrAssembly.findType("System.Data.SqlClient.SqlConnection"); IClrObject sqlConnection = TClrActivator.createInstance(sqlConnectionType); displayObjectTypeInfo(sqlConnection.toObject()); } static void createInstanceUsingTypeWithNoConstructorParameters() throws EClrError { //Create Instance with a parameter Object[] objects = new Object[]{"Data Source=myServerAddress;Initial Catalog=myDataBase;" + "User ID=myDomain\\myUsername;Password=myPassword;"}; //<Change Me> //Assembly has been loaded in CreateInstance2, no need to reload assembly IClrType sqlConnectionType = TClrAssembly.findType("System.Data.SqlClient.SqlConnection"); IClrObject sqlConnection = TClrActivator.createInstance(sqlConnectionType, objects); displayObjectTypeInfo(sqlConnection); } public static void main(String[] arg) { System.out.println(" Hello! Welcome to dotNet4Java "); System.out.println("=================================================="); System.out.println("The program demonstrate how to use Activator Class"); System.out.println("to create an instance of a .Net Object. "); System.out.println(); try { loadAssembly(); createInstanceUsingTypeName(); createInstanceUsingType(); createInstanceUsingTypeWithNoConstructorParameters(); } catch (EClrError eClrError) { eClrError.printStackTrace(); } } }