DotNet::Services.RegisterClass Method


dim Result as L = RegisterClass(ParentNamespace as C, AssignedClassName as C, SourceClassName as C, Assembly as DotNet::AssemblyReference = null_value())



If an empty string is provided, the class is registered under the DotNet namespace.


If an empty string is provided the class is registered using the full class name. All namespaces in the path will be added to the parent namespace.



If not supplied, the class will be loaded from the GAC. If the Assembly is not provided and the class is not in the GAC, the registration will fail.



Returns .t. or .f. whether or not the operation succeeds. The DotNet::Services CallResult property will contain additional information about the error.


Connects a single class in a .NET assembly to the Alpha Anywhere type system within a namespace.


RegisterClass() connects a single class in a .NET assembly to the Alpha Anywhere type system within a namespace. Once the class is registered, which is required once per execution of Alpha Anywhere, instances can be DIMmed in any script.

Before writing production code that uses this method inside a function, consider creating a class wrapper as described in this article.
You can completely rename the type (from the Xbasic perspective) and use the new name whenever you DIM a variable of that type.

 Examples of registration results:

Parent Namespace

Assigned ClassName

Source ClassName

Resulting Type













 Example Usage:

Registering a system type.

Dim Services as DotNet::Services
If Services.RegisterClass( "MyNameSpace", "StringBuilder",\
 Dim Instance as MyNameSpace::StringBuilder
 UI_Msg_Box("Error registering class " + Assy.FullName,\
End if

The StringBuilder class is cached in the GAC, so this registration will succeed. Some less-used System classes are not cached in the GAC and will require an assembly reference to load successfully. The DotNetPath function can be used to supply the standard location for the DLLs in the System and Microsoft namespaces.

You can easily determine if a class is in the GAC using the Alpha Anywhere Interactive window:

dim Sv as DotNet::Services
? Sv.RegisterClass("", "", "")
= .F.

? Sv.RegisterClass("", "", "System.Text.StringBuilder")
= .T.

See the Big Integers example for working code to register a class in the System or Microsoft namespace that is not in the GAC.

Registering a single class from an assembly on disk:

Dim Services as DotNet::Services
Dim Assy as DotNet::AssemblyReference
Assy.FileName = "System.Numerics.BigInteger"

If Services.RegisterClass("MyNameSpace", "", "", Assy)
    Dim Instance as MyNameSpace::StringBuilder
    UI_Msg_Box("System.Text.StringBuilder" + \
End if

While the Assy.FileName in this example is given without a full path, it is often necessary to provide a full path to register a class successfully from a DLL.