From 0529e2c921fb34d52de3d7526f997fb01f82e9e4 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 31 Jul 2020 20:58:25 +0200 Subject: [PATCH] throw if no parameterless constructor was found --- MLEM.Data/CopyExtensions.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/MLEM.Data/CopyExtensions.cs b/MLEM.Data/CopyExtensions.cs index f701720..8823a80 100644 --- a/MLEM.Data/CopyExtensions.cs +++ b/MLEM.Data/CopyExtensions.cs @@ -74,7 +74,10 @@ namespace MLEM.Data { } private static object Construct(Type t, BindingFlags flags) { - return t.GetConstructor(flags, null, Type.EmptyTypes, null).Invoke(null); + var constructor = t.GetConstructor(flags, null, Type.EmptyTypes, null); + if (constructor == null) + throw new NullReferenceException($"Type {t} does not have a parameterless constructor with the required visibility"); + return constructor.Invoke(null); } }