The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Runtime Binding: Class.forName Semantics

Visual Studio 2005

Classes loaded using the Class.forName API are dynamically bound to the application at run time.

The Class.forName(String className) method does not use the CLASSPATH environment variable to locate classes. Instead, a search for classes is conducted in the following locations, in order:

  1. The calling assembly

  2. All assemblies currently loaded into the current application's AppDomain

  3. Assemblies specified in the <CODEBASE> tag of the application configuration (.config) file

  4. The ApplicationBase of the application

  5. All managed DLLs found in the directories specified by the <PROBING> tag of the application configuration file

The search terminates if the class is found at a particular step. If no configuration file is found, or if errors are encountered in parsing the configuration file, steps 3 and 5 are skipped. If the class is not found in any of the steps, ClassNotFoundException is thrown.

Visual J# also provides an additional method in the class java.lang.Class for locating and loading classes from an assembly, as follows:

Class.forName(String assemblyName, String className, boolean absolutePath)

This method searches for the class specified by the className parameter in the assembly specified by the assemblyName parameter. The assemblyName parameter should specify the display name of the assembly (see AssemblyName Class for more information). If the Boolean parameter absolutePath is True, then assemblyName represents an absolute path that specifies the location of the assembly. If absolutePath is False, then it is assumed that no path has been specified and the common language runtime assembly search heuristics are used to locate and load the assembly. If the class is not found in the specified assembly or the specified assembly could not be found, ClassNotFoundException is thrown.

For more information, see Global Assembly Cache, Assemblies, Application Domains, and How the Runtime Locates Assemblies.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft