Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
Support for Dynamically Loaded assemblies
Programmer's Guide > OpenAccess ORM Classic (Old API) > Programming With OpenAccess > Configuration File > Support for Dynamically Loaded assemblies

Glossary Item Box

This documentation article is a legacy resource describing the functionality of the deprecated OpenAccess Classic only. The contemporary documentation of Telerik OpenAccess ORM is available here.

When dynamically loaded assemblies try to open an OpenAccess ORM database, they might encounter the following exception:

The openaccess section cannot be found in the application's configuration file.

The actual exception might even be completely different, depending on the wrapping of the dynamic loading; for e.g., an AutomationException might occur when using COM Interop from VB6.

This exception occurs because there is either no entry assembly or no references path under which the runtime can resolve the configuration file.

To improve this situation, there is a new method added in the ObjectScopeProvider source code with the name AdjustForDynamicLoad(). This method should be called before any other method on the generated ObjectScopeProvider.

The code for the AdjustForDynamicLoad() function is similar to:

C# Copy Code
internal static void AdjustForDynamicLoad()
{
 
if (theObjectScopeProvider1 == null)
 {
   theObjectScopeProvider1 =
new ObjectScopeProvider1();

   
string assumedInitialConfiguration =
     
"<openaccess>" +
       
"<references>" +
         
"<reference assemblyname='PLACEHOLDER' configrequired='True'/>" +
       
"</references>" +
     
"</openaccess>" +
   System.Reflection.Assembly dll = theObjectScopeProvider1.GetType().Assembly;
   assumedInitialConfiguration = assumedInitialConfiguration.Replace(
                 
"PLACEHOLDER", dll.GetName().Name);
   System.Xml.XmlDocument xmlDoc =
new System.Xml.XmlDocument();
   xmlDoc.LoadXml(assumedInitialConfiguration);
   Database db = OpenAccess.Database.Get(
"DatabaseConnection1", xmlDoc.DocumentElement,
                
new System.Reflection.Assembly[] { dll } );

   theObjectScopeProvider1.myDatabase = db;
 }
}