Преглед изворни кода

Attempted to fix a random DatabaseSchema "Collection has been modified" error

frogsoftware пре 1 година
родитељ
комит
41f83576f2
1 измењених фајлова са 14 додато и 4 уклоњено
  1. 14 4
      InABox.Core/DatabaseSchema/DatabaseSchema.cs

+ 14 - 4
InABox.Core/DatabaseSchema/DatabaseSchema.cs

@@ -248,10 +248,20 @@ namespace InABox.Core
         private static void CheckProperties(Type type)
         {
             var entityName = type.EntityName();
-            var props = _properties.GetValueOrDefault(entityName);
-            var hasprops = props?.Any(x => x.Value is StandardProperty) == true;
-            if (type.IsSubclassOf(typeof(BaseObject)) && !hasprops)
-                RegisterProperties(type);
+            try
+            {
+                var props = _properties.GetValueOrDefault(entityName);
+                var hasprops = props?.ToArray().Any(x => x.Value is StandardProperty) == true;
+                if (type.IsSubclassOf(typeof(BaseObject)) && !hasprops)
+                    RegisterProperties(type);
+            }
+            catch (Exception e)
+            {
+                // This seems to be an intermittent error "Collection has been modified" when checking if the Dictionary has been populated already
+                // I've added a .ToArray() to concretise the list, but who knows?
+                Logger.Send(LogType.Error,"",$"Error Checking Properties for Type: {entityName}\n{e.Message}\n{e.StackTrace}");
+            }
+
         }
 
         public static IEnumerable<IProperty> Properties(Type type)