Can't call ModelInfoProviderSingleton.GetInstance().Init()

Posts   
 
    
SanderF
User
Posts: 125
Joined: 11-Dec-2006
# Posted on: 08-Jun-2018 11:25:24   

Hi,

I've migrated our source from v5.3 to v5.4. I used in v5.3 the FieldInfoProviderSingleton and i noticed that this one disappeared in v5.4. So now i'm using then ModelInfoProviderSingleton.

I our program it is possible for users to add new fields in the database via the user interface, after that we call the FieldInfoProviderSingleton.Init() method again for reloading the fields (i've made this method public in FieldInfoProvider.cs).

With the FieldInfoprovider it was possible to "reload" the provider with the Init() method. When i want to reload the MethodInfoProvider i get the following error when this.AddElementFieldInfo is executed for the second time when the field already exists (see attachment).

The question is: how can i "reload" the provider at runtime? I can't find a method to clear the Infoprovider first for example.

Extra information: I've added some custom code in the FieldInfoProvider.cs (and now in the ModelInfoProvider) to support additional fields. Code fragement (see initCustomFieldsForEntity method on the bottom):

private void InitBouwBasislijstProductRelatieEntityInfo()
        {
            this.AddFieldIndexEnumForElementName(typeof(BouwBasislijstProductRelatieFieldIndex), "BouwBasislijstProductRelatieEntity");
            this.AddElementFieldInfo("BouwBasislijstProductRelatieEntity", "ID", typeof(System.Int32), true, false, true, false,  (int)BouwBasislijstProductRelatieFieldIndex.ID, Tools.GetSourceColumnMaxLength("IMS_BasislijstenProdRel", "BPRKeyID", 0), 0, 10);
            this.AddElementFieldInfo("BouwBasislijstProductRelatieEntity", "BPKeyID", typeof(System.Int32), false, true, false, false,  (int)BouwBasislijstProductRelatieFieldIndex.BPKeyID, Tools.GetSourceColumnMaxLength("IMS_BasislijstenProdRel", "BPRBPKeyID", 0), 0, 10);
            this.AddElementFieldInfo("BouwBasislijstProductRelatieEntity", "PDRKeyID", typeof(System.Int32), false, true, false, false,  (int)BouwBasislijstProductRelatieFieldIndex.PDRKeyID, Tools.GetSourceColumnMaxLength("IMS_BasislijstenProdRel", "BPRPDRKeyID", 0), 0, 10);
            this.AddElementFieldInfo("BouwBasislijstProductRelatieEntity", "InvoerNaam", typeof(System.String), false, false, false, true,  (int)BouwBasislijstProductRelatieFieldIndex.InvoerNaam, Tools.GetSourceColumnMaxLength("IMS_BasislijstenProdRel", "BPRInvoerNaam", 255), 0, 0);
            this.AddElementFieldInfo("BouwBasislijstProductRelatieEntity", "InvoerDatum", typeof(Nullable<System.DateTime>), false, false, false, true,  (int)BouwBasislijstProductRelatieFieldIndex.InvoerDatum, Tools.GetSourceColumnMaxLength("IMS_BasislijstenProdRel", "BPRInvoerDatum", 0), 0, 0);
            this.AddElementFieldInfo("BouwBasislijstProductRelatieEntity", "WijzigNaam", typeof(System.String), false, false, false, true,  (int)BouwBasislijstProductRelatieFieldIndex.WijzigNaam, Tools.GetSourceColumnMaxLength("IMS_BasislijstenProdRel", "BPRWijzigNaam", 255), 0, 0);
            this.AddElementFieldInfo("BouwBasislijstProductRelatieEntity", "WijzigDatum", typeof(Nullable<System.DateTime>), false, false, false, true,  (int)BouwBasislijstProductRelatieFieldIndex.WijzigDatum, Tools.GetSourceColumnMaxLength("IMS_BasislijstenProdRel", "BPRWijzigDatum", 0), 0, 0);

            // IDB specifiek: vrije velden toevoegen        
            initCustomFieldsForEntity("BouwBasislijstProductRelatieEntity", "IMS_BasislijstenProdRel");
        }
Attachments
Filename File size Added on Approval
Error with ModelInfoProviderSingleton.jpg 627,961 08-Jun-2018 11:25.39 Approved
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-Jun-2018 11:36:40   

When i want to reload the MethodInfoProvider i get the following error when this.AddElementFieldInfo is executed for the second time when the field already exists (see attachment).

The exception attached is for AddEntityInfo(), please confirm.

SanderF
User
Posts: 125
Joined: 11-Dec-2006
# Posted on: 08-Jun-2018 11:46:57   

Yes, that's right, i've added an additional screenshot.

Attachments
Filename File size Added on Approval
Error AddEntityInfo.jpg 278,452 08-Jun-2018 11:47.01 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 11-Jun-2018 10:11:32   

It's not really recommended nor supported to do this, as all this data is static and assumed readonly. This means that if you reload this data at runtime when the application is already running, it might lead to unwanted results.

That said, the ModelInfoProvider's Init() method calls the InitClass() method of the FieldInfoProvider, which simply re-initializes its datastructures. Re-running the init methods then should simply rebuilt the objects. It doesn't re-initialize the InheritanceInfoProvider though. So dynamically introducing inheritance is a no go area.

So in short: I don't really see how you could get duplicated elements when the InitClass() method simply starts over so the original objects are no longer there...

Frans Bouma | Lead developer LLBLGen Pro