From 215e1f650028d044f90f3e606c6b56eced8944a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Mon, 25 Dec 2023 20:25:55 +0100 Subject: [PATCH] Catch Activator exceptions --- ScriptCore/Serialization/EntitySerializer.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ScriptCore/Serialization/EntitySerializer.cs b/ScriptCore/Serialization/EntitySerializer.cs index 4b037a7..f6a6454 100644 --- a/ScriptCore/Serialization/EntitySerializer.cs +++ b/ScriptCore/Serialization/EntitySerializer.cs @@ -323,7 +323,24 @@ public static class EntitySerializer if (type == null) return context; - context._instance = Activator.CreateInstance(type); + try + { + context._instance = Activator.CreateInstance(type, true); + } + catch (MissingMethodException e) + { + Log.Error($"Failed to create instance of type \"{type}\": The type doesn't contain a constructor with zero parameters.\nMake sure the type has a constructor that takes no arguments (It can be private!).\n{e}"); + } + catch (MethodAccessException e) + { + Log.Error($"Failed to create instance of type \"{type}\": The default constructor is not accessible.\n{e}"); + } + catch (Exception e) + { + Log.Error(e); + + return context; + } if (context._instance == null) return context;