Problem while switching database at runtime

4 posts, 0 answers
  1. Christoph
    Christoph avatar
    7 posts
    Member since:
    Jul 2010

    Posted 23 Jul 2010 Link to this post

    Dear Telerik support team,

    I have encounterred a problem while switching open access databases at runtime. The error message says:

    "The config file reference for assembly '<assemblyname>' could not be resolved. Make sure that the referencing assembly uses at least one class of the referencing assembly as otherwise the compiler won't generate a reference."

    I have an application with a presentation-, a business-, and a data access-layer. In the data access-layer I am switching the database dynamically at runtime to provide access to different customer databases. Depending on which customer is logging in, the proper database is loaded. For this, the business-layer contains all the business entities I am mapping with open access. All customer databases have the same mapping and entities.

    This works fine when I add an object from a business-layer class in the data access-layer (e.g. BusinessLayer.Entities.User user). But when I do so, I violate the rules of assembly references for my project, because the business-layer may reference the data access-layer, but not the other way around.

    Do you have any solution to solve this problem or a architecture suggest? Maybe there is a way to reference the assembly in the reference section of the config file without instantiate an object from BusinessLayer.Entities in the data access-layer. I override the config file at runtime by using the function AdjustForDynamicLoad() in the ObjectScopeProvider class (which is in the data access-layer). 

    Kind regards,

    Christoph Tuchan
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 23 Jul 2010 Link to this post

    Hello Christoph,

    As the exception says, it is possible that you are not using in the executable project any of the classes from the referenced assembly? In such cases the reference to this assembly is omitted and the configuration cannot be loaded. If this is the case, please make sure you are using at least one class from the model assembly.
    Telerik OpenAccess ORM needs to know of all assemblies used by the application, which contains persistent capable classes. These assemblies are listed within the reference section in the configuration file. If such assembly is not referenced, the reference cannot be resolved, and “The config file reference for assemblyname <assemblyname> could not be resolved" exception will be thrown.
    I recommend that you read this help article which explains how to use configuration files for class libraries.
    Hope that helps.

    Greetings,
    Damyan Bogoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Christoph
    Christoph avatar
    7 posts
    Member since:
    Jul 2010

    Posted 27 Jul 2010 Link to this post

    Dear Telerik Support,

    thanks for the quick reply. I could solve the problem, but not by rewriting the app.config files. Instead I fixed the following mistake:

    In the method AdjustForDynamicLoad() I was loading the executing DLL out of the ObjectScopProvider1 (by using System.Reflection.Assembly dll = theObjectScopeProvider1.GetType().Assembly). This always was my data access layer DLL. When I tried to load the database, OpenAccess tried to map the business entities by using this DLL... which was wrong. Now I dynamically load the neccessary DLL by using the AdjustForDynamicLoad-method like this:

    AdjustForDynamicLoad(System.Reflection.Assembly callingAssembly)
    {
       // Build new ConfigString
       ...
       // Load Database by using calling assembly
       Database db = Telerik.OpenAccess.Database.Get(connection,
                      xmlDoc.DocumentElement, new System.Reflection.Assembly[] { callingAssembly});
    }

    Thanks anyway!

    Kind regards

    Christoph
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 27 Jul 2010 Link to this post

    Hello Christoph,

    We are glad to see that you have solved the problem. If any other questions arise please contact us back.

    Sincerely yours,
    Damyan Bogoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top