DynamicDataStore refuses to add new properties

Vote:
 

Hi!

I am really stuck at something. I am trying to add a new property to an existing DynamicDataStore, but if I do, I get a nullreference exception on 

the get store call:

DynamicDataStoreFactory.Instance.GetStore(typeof(T))

My class looks like this, and I am trying to add the PluralName property:

    [EPiServerDataStore(AutomaticallyRemapStore = true, AutomaticallyCreateStore = true)]
    [EPiServerDataContract]
    public class Ingredient : IDynamicData
{
(...)
      [EPiServerDataMember]
      public string PluralName { get; set; }
}

I have tried to add an initialization module that remaps the store, but no luck.

What am I doing wrong?

#246456
Edited, Jan 06, 2021 13:43
Vote:
 

Hi Torunn

A NullReferenceException can happen in a lot of places. It will be easier to pitch in, if you can post the stack trace of the exception.

#246461
Jan 06, 2021 17:04
Vote:
 

The only stack trace is this:

Object reference not set to an instance of an object.

at EPiServer.Data.Dynamic.Internal.EPiServerDynamicDataStoreFactory.GetStore(Type type)

#246464
Jan 06, 2021 18:23
Vote:
 

It should update the store in the database, and add the new field. But instead, it seems to complain that the store doesn't comply with the code.

It worked in test, but not in production. I copied the database from production to development, and the same error occurs there. The store doesn't have a name set in code,

and if I do, it also fails with the same exception.

#246492
Edited, Jan 07, 2021 7:20
Vote:
 

So after digging some more, the error seems to be there before I add the new property.

It can't remap.

ingredientStore.StoreDefinition.Remap(ingredientType);
            try
            {
                ingredientStore.StoreDefinition.CommitChanges();
            }
            catch (NullReferenceException exc)
            {

The stack trace is:

   at EPiServer.Data.Dynamic.Providers.SqlServerDataStoreProvider.GetStoreInfoSaveCommand(StoreDefinition storeDefinition)
   at EPiServer.Data.Dynamic.Providers.SqlServerDataStoreProvider.<>c__DisplayClass36_0.<SaveStoreDefinition>b__0()
   at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass32_0.<ExecuteTransaction>b__0()
   at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass33_0`1.<ExecuteTransaction>b__0()
   at EPiServer.Data.Dynamic.StoreDefinition.<>c__DisplayClass87_1.<CommitChanges>b__1()
   at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass32_0.<ExecuteTransaction>b__0()
   at EPiServer.Data.Providers.Internal.SqlDatabaseExecutor.<>c__DisplayClass33_0`1.<ExecuteTransaction>b__0()
   at EPiServer.Data.Providers.SqlTransientErrorsRetryPolicy.Execute[TResult](Func`1 method)
   at EPiServer.Data.Dynamic.StoreDefinition.<>c__DisplayClass87_0.<CommitChanges>b__0()
   at EPiServer.Data.Cache.Internal.LocalCache`2.Add(TKey key, Boolean cacheNullValues, Boolean overwriteExistingValue, Func`1 getAction, Action`2 setAction)
   at EPiServer.Data.Cache.Internal.LocalCache`2.Add(TKey key, Boolean cacheNullValues, Boolean overwriteExistingValue, Func`1 action)
   at EPiServer.Data.Dynamic.StoreDefinition.CommitChanges(DataStoreProvider provider)
   at ...IngredientsInitialization.Initialize(InitializationEngine context) in ...\IngredientsInitialization.cs:line 49

I even tried to clear the cache.

 CacheProvider.Instance.ClearStore(ingredientStore.StoreDefinition.StoreName);

Any help is appreciated!

#246530
Jan 08, 2021 8:31
Vote:
 

Deleting the store helped, but I obviously can't do that in production. 

#246531
Jan 08, 2021 9:52
Vote:
 

You can try to fall back to create store if getstore returns null. Something like

var store = GetStore(type) ?? CreateStore(type)

#246532
Jan 08, 2021 9:53
Vote:
 

Yes, I did, but the createstore also fails with nullreferenceexception.

#246536
Jan 08, 2021 10:41
Vote:
 

I couldn't figure this out, so I ended up saving the new properties in a new store. Not ideal, but it seems there are some inconsistency in the data, that

causes this error.

#246639
Jan 11, 2021 13:48
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.